keyongtech


  keyongtech > dotnet.languages.* > dotnet.languages.csharp > 08/2008

 #1  
08-07-08, 07:07 AM
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
 #2  
08-07-08, 08:20 AM
Jon Skeet [C# MVP]
On Aug 7, 7:07 am, ph_haen...@yahoo.de wrote:
> 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
Similar Threads
Question about LinQ (LinQ to Sql)

I have already heard that LinQ to Sql will be replaced by LinQ to Entities or something like that. My question is below: that the whole concept of LinQ whatever -- it is...

Linq to XML--Are there code examples that make Linq as easy as SQL? Or how can I convert ths simple pseudo code into real code?

Maybe I shouldn't be using XML for what I want. I want to store some program data and retrieve it easily, iterating through elements grabbing child elements easily and...

Mixing linq to sql and linq to xml (in linqpad)

Hi group, In my database, I have a table with fields like this : id | title | xml ------------------------------------ 1 | title1 | ...

Linq to SQL - Return DataTable as a result of Linq query

Hi! How to get result od dataTable from Linq query? I have typied DataSet and I want to join couple of tables. And I have a problem with change this result to DataTable...

LINQ

Is LINQ to SQL supported in the 3.0 Framework or is it only available in 3.5? Thanks, JP


All times are GMT. The time now is 01:41 PM. | Privacy Policy