Combination of Linq to sql and Linq to xml

P

ph_haenggi

Hi folks

I am pretty new to linq and in one of my first samples I tried to do
the following:

In my sample-database I have a table which has some columns and one of
them has the type 'xml'.

sample-data

ID varcharcolumn1 varcharcolumn2 xmlcolumn
1 test test
<xml><name>Test</name></xml>
2 test2 test2
<xml><name>nodata</name></xml>


Is it possible to get all Rows where the xml-Column has a node 'name'
with a Textnode that starts with 'T' using LINQ?

Thanks

Philipp Haenggi
 
J

Jon Skeet [C# MVP]

I am pretty new to linq and in one of my first samples I tried to do
the following:

In my sample-database I have a table which has some columns and one of
them has the type 'xml'.

sample-data

ID      varcharcolumn1    varcharcolumn2    xmlcolumn
1           test                      test
<xml><name>Test</name></xml>
2           test2                    test2
<xml><name>nodata</name></xml>

Is it possible to get all Rows where the xml-Column has a node 'name'
with a Textnode that starts with 'T' using LINQ?

Not easily - because the query is performed at the database side. If
the database has knowledge of XML there may be special SQL extensions
you could use - but they won't be generated by LINQ to SQL. You may be
able to get away with a regular expression (or simply use LIKE and
"<name>T" but that will be error prone if there could be attributes in
the elements etc. To actually use LINQ to XML to do the querying,
you'd have to pull all the XML from the database and then do the query
in-process.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top