Reputation: 957
I have an issue. Perhaps one of you experts can help out here. The table that I am querying has 2 xml columns. I need to perform query on xml data in these columns too ( in my advanced search functionality ). Problem is I am using Entity Framework and it doesnt support that. Even if I try to do "ObjectQuery.Execute" it causes Syntax Error. So what are my options here ?
Thanks,
Ali Nahid
Upvotes: 6
Views: 4096
Reputation: 5803
EF maps SQL Server XML type columns to strings. So for this definition:
CREATE TABLE [dbo].[XmlData](
[ID] [int] IDENTITY(1,1) NOT NULL,
[XmlTestColumn] [xml] NOT NULL
)
you would have the following entity:
public partial class XmlData
{
public int ID { get; set; }
public string XmlTestColumn { get; set; }
}
and would be able load the string into XmlDocument, etc. That's one approach.
If you prefer to issue a native XML query against SQL Server, you'll need to
Use Database.SqlQuery
with a your XML query:
var query = context.Database.SqlQuery(@"SELECT it.Id, it.Name, it.SomeData, t2.someotherdata FROM Table1 as it CROSS APPLY ...");
ObjectQuery
works against the conceptual model and does not support native queries.
Upvotes: 4