Combination of Linq to sql and Linq to xml

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ph_haenggi@yahoo.de

    Combination of Linq to sql and Linq to xml

    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>noda ta</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

  • Jon Skeet [C# MVP]

    #2
    Re: Combination of Linq to sql and Linq to xml

    On Aug 7, 7:07 am, ph_haen...@yaho o.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>noda ta</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

    Comment

    Working...