One problem you may have come across when getting data from your data service is the problem of how to "flatten it" so you can bind to, for example, a gridview. The problem with dataservices is that they don't allow either projection or joins. For instance this:
dim c = (from t in ctx.tblCustomers select t.customername, t.CustomerType.customertype)
will not work. Linq to dataservices can't express this as XML.
The trick is to grab all the data you need by enumerating it THEN do the join. Once enumerated the data can be manipulated via linq to objects. So this will work
Assuming you have used expand to add the related tables...
dim lst = (from t in ctx.tblCustomers).ToList
dim lst_flattened = (from t in lst select t.customername, t.CustomerType.customertype)
gvwCustomer.DataSource = lst
etc
Be aware that lst is now an anonymous type. If you need to return it from a function then you need to create your own type and then select into it.
Wednesday, 19 November 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment