New Posts New Posts RSS Feed: From Class to Linq
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

From Class to Linq

 Post Reply Post Reply
Author
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Topic: From Class to Linq
    Posted: 23-Jul-2010 at 11:23am
Queries in Silverlight (which I assume you're using since you posted in this forum) must be asynchronous unless directed against the local cache. So the basic query would look something like this:


      var vendorsQuery = entityManager.Vendors
        .OrderBy(v => v.VendorName);
      _em1.ExecuteQueryAsync<Vendor>(vendorsQuery, GotVendors, null);
...
    private void GotVendors(EntityQueryOperation<Vendor> op) {
      ObservableCollection<Vendor> vendors =
        new ObservableCollection<Vendor>();
      op.Results.ForEach(v => vendors.Add(v));
    }


or using the anonymous method syntax,


      var vendorsQuery = entityManager.Vendors
        .OrderBy(v => v.VendorName);
      entityManager.ExecuteQueryAsync<Vendor>(vendorsQuery, op => {
        ObservableCollection<Vendor> vendors =
          new ObservableCollection<Vendor>();
        op.Results.ForEach(v => vendors.Add(v));
      },
      null);
    }


If you want write a FetchVendors method, you'll need to pass it a callback method so it can "phone" your calling method back when the results have been returned from the asynchronous query operation. For an example of that, see the GetEmployeeWithTotalOrderRevenueAsyncMethod() mini-demo in the Silvermight MiniDemos solution for Object Persistence, described here:

DevForce 2010 Documentation » Business Object Persistence » Code Sample - Mini-Demos (Silverlight)
Back to Top
BillG View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
Post Options Post Options   Quote BillG Quote  Post ReplyReply Direct Link To This Post Posted: 22-Jul-2010 at 4:43pm
I used to write a retrieval query like this
EntityList<Customer> customers = myPM.GetEntities<Customer>(query);
 
 
And then I would pass the customers object to a data grid.
 
How do I do the same in Linq
 
This is what I have so far:
 

private readonly TicketWareEntities entityManager = TicketWareEntities.DefaultManager;

public ObservableCollection<Vendor> Vendors { get; private set; }

public ????? FetchVendors()

{

var query = from Vendor in entityManager.Vendors

orderby Vendor.VendorName

select Vendor;

????? = entityManager.ExecuteQuery<Vendor>(query);

return ?????

}
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down