Now , it happens that you go to McDonalds website and order an item for you. It could happen that price of the menu changed or new one comes to the menu. Now, generally it can happen that admin can go though wizard and loads of textboxes or dropdowns to make the changes or he/she can just write as if he/she is writing in some text editor and everything else is taken care of on behalf. Textual DSL is a powerful tool that might become the future of how we communicate to computer systems. Well, things are not that easy to convert human language to machine readable forms completely but its not bad to dream for the best :-).
In this post, i will show how you can change items using M and then bind it to a data grid using LINQ query. I will do it using sample data that shows price menu for Mc burgers.
Our first step is to define a constant that holds the M value format.
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 need to bind it to a data grid,
1: gridView1.DataSource = mcContext;
2: gridView1.DataBind();
Now, this for when you are just getting your data and binding it to the grid without any type of filters, to use filter let’s construct a class around the items, let’s call it McBurger, actually internally it infers to the class that we have defined rather building a anonymous type.
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 do 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 data grid 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. You will be needing Oslo May CTP to run this sample.
Hope that helps
