Hello and thanks in advance for the help.
I have a sql table hosted on a server that has two columns: ID(int), server_info(xml)
The xml entries in this table look like this:
<ServerID>11</ServerID><GroupID /><ParentID>15</ParentID><ServerName>IAProd1</ServerName><User>admin</User><UID>123</UID><PWD>password</PWD><Domain>TestDomain</Domain><Location>Left</Location>
This table is represented within my Silverlight application as a ADO.Net data entity data model. I want to have a parameterized query called via the WCF service that takes an Id number and finds the children in the server table based on their parent id value which is embedded within the xml of their server_info column.
On the sql server I can do this using the following query with an xpath statment:
<!--uses xpath statement in the where clause:(server_info.value('(ServerID)[1]', 'int') = 11) -->
SELECT ID, server_info
FROM tbl_server_xml
WHERE (server_info.value('(ServerID)[1]', 'int') = 11)
Currently my query method looks something like this:
public List<tbl_server_xml> getChildServers(int parentId)
{
//create instance of Ado.Net entity
xMonitorXMLTestDBEntities db = new xMonitorXMLTestDBEntities();
var item = from entry in db.tbl_server_xml
where //need assistance with the where clause
select entry;
}
I have not been able to figure out how to do the equivalent with just a linq query in the service method or a way to integrate xpath statements into Linq queries. Is there a way to do this or am I going about this wrong? Thank you again for the help.
The problem is that your
server_infois not a valid XML document content because it have no root element. But with a simple trick you could write your query like thisor using plain Linq to XML