An early alpha of Linq to SqlXml is now available on github: https://github.com/calyptus/linq-to-sqlxml
There is no documentation nor setup scripts so you’re on your own if you try it.
If you get it to run, be sure to add all indexes to the xml field – primary , secondary – path , secondary – value , secondary – property
I’m hacking along on my Document DB emulator ontop of Sql Server XML columns.
I have some decent Linq support in place now.
The following query:
var query = from order in orders
//must have status shipped
where order.Status >= OrderStatus.Shipped
//must contain foo or bar products
where order.OrderDetails.Any(d => d.ProductNo == "Foo" || d.ProductNo == "Bar")
//must have an order total > 100
where order.OrderDetails.Sum(d => d.ItemPrice * d.Quantity) > 100
will yield the following Sql + XQuery to the Sql Server:
where CollectionName = 'Order' and
--must have an order total > 100
for $A in OrderDetails/object/state
return ($A/ItemPrice * $A/Quantity)) > xs:decimal(100))]') = 1) and
--must contain foo or bar products
(documentdata.exist('/object/state[OrderDetails/object/state[((ProductNo = "Foo") or
(ProductNo = "Bar"))]]') = 1) and
--must have status shipped
(documentdata.exist('/object/state[(Status >= xs:int(2))]') = 1)
I’ve started to build a Document DB emulator ontop of Sql Server XML columns.
Sql Server XML columns can store schema free xml documents, pretty much like RavenDB or MongoDB stores schema free Json/Bson documents.
XML Columns can be indexed and queried using XPath queries.
So I decided to build an abstraction layer ontop of this in order to achieve similair ease of use.
I’ve built a serializer/deserializer that deals with my own XML structure for documents (state + metadata) and also an early Linq provider for querying.
Executing the following code:
var ctx = new DocumentContext("main");
var customers = ctx.GetCollection<Customer>().AsQueryable();
var query = from customer in customers
where customer.Address.City == "abc" && customer.Name == "Acme Inc5"
var result = query.ToList();
foreach (var item in result)
Will yield the following SQL + XPath query:
where CollectionName = 'Customer' and
((documentdata.exist('/object/state/Address/object/state/City/text()[. = "abc"]') = 1) and
(documentdata.exist('/object/state/Name/text()[. = "Acme Inc5"]') = 1))
order by documentdata.value('((/object/state/Name))','nvarchar(MAX)')
The result of the query will be returned to the client and then deserialized into the correct .NET type.