Subsonic - 按 XML 列数据类型过滤
我已经下载了 Subsonic 3.0.0.3,并且我的 MSSQL 数据库中有一个 XML 数据类型。该属性以字符串形式返回,这很好,但是如何创建一行代码来按该列中的内容进行过滤。
如果我尝试类似 from x in Table.All() where x.XMLColumn.Contains("test")
的操作,它会抛出异常,因为虽然该属性是一个字符串,并且上面的内容在它变成时会编译它到 SQL 中对于该列类型是不正确的。
I have downloaded Subsonic 3.0.0.3 and I have a XML DataType in my MSSQL database. The property comes back as a string which is fine however how do I create a line of code to filter by contents in that column.
If I try something like from x in Table.All() where x.XMLColumn.Contains("test")
it throws an exception because although the property is a string and the above will compile when it turns it into SQL its incorrect for that column type.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有趣 - 我还没有遇到过在数据库调用中查询 XML,但我可以看到它有什么用处。为了解决您的问题,我建议您现在使用 SPROC 或使用简单查询工具,它可以更好地明确工作。
http://subsonicproject.com/docs/Simple_Query_Tool
您还可以使用 CodingHorror,它允许您编写自己的自己的 SQL(参数化)
http://subsonicproject.com/docs/CodingHorror
Interesting - I haven't run into querying XML inside of a DB call but I can see how it would be useful. To get you around your issue I would suggest using a SPROC for now or using the Simple Query tool which does a better job of being explicit.
http://subsonicproject.com/docs/Simple_Query_Tool
You can also use CodingHorror which allows you to write your own SQL (parameterized)
http://subsonicproject.com/docs/CodingHorror
另一种选择是将属性值转换为对象,然后调用其
ToString()
方法。这会导致 Subsonic linq 提供程序将 XMLColumn 值显式转换为NVARCHAR(MAX)
。您需要强制转换,因为 Linq 提供程序在转换为 SQL 时会忽略
String.ToString()
方法调用。这是一种 hack,但它确实解决了问题。Another option is to cast the property value as an object and then call its
ToString()
method. This causes the Subsonic linq provider to explicitly convert the XMLColumn value toNVARCHAR(MAX)
.You need the cast because the Linq provider will ignore
String.ToString()
method calls when translating to SQL. This is kind of a hack, but it does get around the problem.