Saturday 15 March 2014

sql - Searching a tables XML filed using Linq, can it be done? -


I have a database table with a transaction in one of the fields in the XML message, the field type is "xml" An employee has been filed in XML and this is the area that I have to find. I want to retrieve all the rows that match the employee number given on the runtime, is it possible to do this with Linq?

Example of XML from one of the rows in the transaction table, here the area is called "message". I need to see the "employee" value and return the line if it is provided by the user Matches the matching mail.

  & lt; Interface & gt; & Lt; Mac & gt; 1452345234 & lt; / Mac & gt; & Lt; Tools & gt; DEVICE1 & lt; / Tools & gt; & Lt; ID & gt; 1234567 & lt; / Id & gt; & Lt; Terminal & gt; & Lt; Unit & gt; 1 & lt; / Unit & gt; & Lt; Trans & gt; & Lt; Event & gt; A3 & lt; / Event & gt; & Lt; Employee & gt; 3333 & lt; / Staff & gt; & Lt; Time & gt; 2008-10-02T11: 41: 00.0000000 + 00: 00 & lt; / Time & gt; & Lt; / Trans & gt; & Lt; / Terminal & gt; & Lt; / Interface & gt;  

Yes, it is easily possible with LINQ:

  var matchList = In the transaction where XDocument.Load (new string reader (T. message)). Candidates ("Employee") Country (node ​​= & gt; node value == employee slogan) & gt; 0 select;  

No comments:

Post a Comment