Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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 to NVARCHAR(MAX).

from x in Table.All() where ((object)x.XMLColumn).ToString().Contains("test")

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top