Linq to SqlXml: Projections

I’ve managed to add projection support to my Linq to Sql Server Xml column implementation.

Executing this Linq query:

var query = (from order in ctx.GetCollection().AsQueryable()
                where order.OrderTotal > 100000000
                where order.ShippingDate == null
                where order.OrderDetails.Sum(d => d.Quantity * d.ItemPrice) > 10
                select new
                    OrderTotal = order.OrderDetails.Sum(d => d.ItemPrice * d.Quantity),
                    CustomerId = order.CustomerId ,
                    Details = order.OrderDetails

Will yeild this Sql + XQuery:

select top 5 Id,DocumentData.query(
'<object type="dynamic">
  <OrderTotal type="decimal">
              for $A in /object[1]/state[1]/OrderDetails[1]/object/state[1] 
                      return ($A/ItemPrice[1] * $A/Quantity[1]))}  </OrderTotal>
  <CustomerId type="guid">
  <Details type="collection">
</object>') as DocumentData

from documents
CollectionName = 'Order'  and

        for $A in /object[1]/state[1]/OrderDetails[1]/object/state 
             return ($A/Quantity[1] * $A/ItemPrice[1])) > xs:decimal(10)) and

/object[1]/state[1]/ShippingDate[1][@type="null"] and
(/object[1]/state[1]/OrderTotal[1] > xs:decimal(100000000))]

')) = 1

One thought on “Linq to SqlXml: Projections”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s