Introducing LINQ to M
1: const string MGraphCode = @"Burgers
2: {
3: { Code=""DCB001"",Name=""Double Cheese Burger"",Quantity=1,Price=5},
4: { Code=""Mc001"",Name=""Mc Chicken"",Quantity=1,Price=4}
5: }";
Next, you need to load the grammar using the QueryContext :
1: var mcContext = QueryContext.Instance.Load(MGraphCode);
And, finally you need to bind it to a datagrid:
1: gridView1.DataSource = mcContext;
2: gridView1.DataBind();
Now, what will be case if you want to do some query before you bind it to the grid. In that case, you need to construct a wrapper class that represents the entity and in our case, let’s call it McBurger which we will be passing as a generic type to the Load method.
1: public class McBurger
2: {
3: public string Code {get;set;}
4: public string Name { get; set; }
5: public int Quantity { get; set; }
6: public float Price { get;set;}
7: }
Accordingly, you can use LINQ statement to query it like:
1: var mcContext= QueryContext.Instance.Load<McBurger>(MGraphCode);
2:
3: var query = from mcBurger in mcContext
4: where mcBurger.Code == "Mc001"
5: select mcBurger;
6:
7: // rest of the databinding code remains the same.
8:
So, we took the context and queried for specific menu and datagrid binding remains the same which brings an output like
Actually, Steve and I are pretty excited about this, the possibility of doing things with M is almost endless. Steve has made a more detail post on this and you can find it right at LINQ to M is available. You can also download the library as well as the sample from Telerik labs and it points to here.
Finally, you can download the example that i have shown from here. By the way, you will be needing Oslo May CTP to run this sample.
Hope that helps