c#linq包含运算符

c#linq包含运算符,c#,xml,linq,windows-phone-7,contains,C#,Xml,Linq,Windows Phone 7,Contains,我正在WP7c#linq和XML进行开发。下面的查询不起作用(无法将类型“bool”转换为“string”)。我需要一些易于使用的类似SQL的操作符。运算符==工作正常 var data = from query in loadedData.Descendants("Row") where ((string)query.Element("Names").Value.Contains("Joh"))

我正在WP7c#linq和XML进行开发。下面的查询不起作用(无法将类型“bool”转换为“string”)。我需要一些易于使用的类似SQL的操作符。运算符==工作正常

var data = from query in loadedData.Descendants("Row")
                         where ((string)query.Element("Names").Value.Contains("Joh"))
                        select new Kalendars
                        {
                            myDate = (int)query.Element("Date"),
                            myMonth = (string)query.Element("Month"),
...
更改:

((string)query.Element("Names").Value.Contains("Joh"))
致:

或者您可以使用更改:

((string)query.Element("Names").Value.Contains("Joh"))
致:


或者您可以使用

您可以尝试将元素强制转换为字符串,而不是Contains的结果:

where ((string)query.Element("Names")).Contains("Joh")

您可以尝试将元素强制转换为字符串,而不是Contains的结果:

where ((string)query.Element("Names")).Contains("Joh")

query.Element(“Names”).Value.Contains(“Joh”)--现在我有了“NullReferenceException”,其中SqlMethods.Like(query.Element(“Names”),“Joh”)导致“与'System.Data.Linq.SqlClient.SqlMethods.Like(string,string)'匹配的最佳重载方法”具有一些无效参数”,如果您得到的是
NullReferenceException
,这意味着要么没有“Names”元素,要么“Names”元素为空。如果您在问题中添加了一个XML示例,这将对我们有所帮助。Names元素不是空的,因为query与==运算符:
where(string)query.element(“Names”)==John,George“
完全正确。问题在于缺少XML值。非常感谢。query.Element(“Names”).Value.Contains(“Joh”)--现在我有了“NullReferenceException”,其中SqlMethods.Like(query.Element(“Names”),“Joh”)导致“与'System.Data.Linq.SqlClient.SqlMethods.Like(string,string)'匹配的最佳重载方法”具有一些无效参数”,如果您得到的是
NullReferenceException
,这意味着要么没有“Names”元素,要么“Names”元素为空。如果您在问题中添加了一个XML示例,这将对我们有所帮助。Names元素不是空的,因为query与==运算符:
where(string)query.element(“Names”)==John,George“
完全正确。问题在于缺少XML值。非常感谢。