Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Linq to entities - what is wrong here.
Message
Information générale
Forum:
ASP.NET
Catégorie:
Silverlight
Divers
Thread ID:
01524523
Message ID:
01524601
Vues:
50
>Bill,
>
>For what it's worth, I have been using Linq To Sql for a long time and I like it. Then I decided to move to EF. There are some things tht you can do in L2S that you cannot to in EF, like
>
>
>public CustomerModel GetCustomer(int CustomerId)
>{
>    CustomerModel retVal = (from c in dc.tblCustomers
>                            where c.CustomerId == CustomerId
>                            select new CustomerModel
>                            {
>                                CustomerId = c.CustomerId,
>                                Invoices = GetInvoicesForCustomer(c.CustomerId)  // <=== Calls another method in this class
>                            }).FirstOrDefault();
>
>    return CustomerModel;
>}
>
>
>The call to GetInvoicesForCustomer won't work in EF becuase the entire statement has to be convertable to a SQL command. Wht you have to do instead is have a series of nested queries using .Include("tablename").
>
>I'm still learning EF but I really hate this restriction.
>
>Th point is, I wonder if you would be more productive, at least at this point, in going with L2S?

What I've done as of this afternoon is just start declaring services in the DomainService that do the entity joins and such that apparently can't be done on the Silverlight client side.The queries I started with work fine at the service level.

This has been a really rought week with this stuff.




>
>
>
>
>>Damn. Obvoiusly I've wasted my time with trying to figure out EF (at least for use with Silverlight).
>>I'll have to learn WCF services and just do all the data access from there apparently.
>>
>>
>>>
>>>(the learning curve I have currently is like climbing a steep mountain of loose gravel)...
>>>
>>>OK. I have a silverlight 4 app. EF datamodel of my SQL database. Domain DataService making my Entities visible.
>>>
>>>Two entity tables are Projects and Change_Requests. Projects has primary key Project_ID. Change Requests has FK Product_ID. Change Requests have a SubdivisionID (int) field.
>>> 
>>>They seem to be functioning as entities correctly. The GetProjectsQuery and GetChange_RequestQuery queries seem to be functional (all built automatically when creating the datamodel and domainservice).
>>>
>>>This works fine..
>>>
>>>            EntityQuery<Project> query = (from P in _Context.GetProjectsQuery()
>>>                                          where P.Proj_Name.Contains(txtFilterProjectName.Text.Trim())
>>>                                          orderby P.Proj_Name
>>>                                          select P);
>>>            LoadOperation<Project> lo = _Context.Load<Project>(query);
>>>
>>>            DataGridProjects.ItemsSource = lo.Entities;
>>>
>>>GetChange_RequestQuery works ok too.
>>>
>>>Now I'm trying to do the equivalent of a join or subquery to get Projects that have Change_Requests in a specific Change_Request.SubdivisionID.
>>>
>>>I've tried..
>>>
>>>            EntityQuery<Project> query = (from p in _Context.Projects
>>>                                          from c in _Context.Change_Requests
>>>                                          where p.Project_ID == c.Project_ID && c.Subdivision == SubdivisionID
>>>                                          select p);
>>>
>>>I get an error ..
>>>Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<ChangeManagement.Web.Project>' to 'System.ServiceModel.DomainServices.Client.EntityQuery<ChangeManagement.Web.Project>'
>>>
>>>OK, let's try using the Getmethods (like the one that worked above)..
>>>
>>>            EntityQuery<Project> query = (from p in _Context.GetProjectsQuery()
>>>                                          from c in _Context.GetChange_RequestQuery()
>>>                                          where p.Project_ID == c.Project_ID
>>>                                              && c.Subdivision.Equals(SubdivisionID)
>>>                                          select p);
>>>
>>>Error..
>>>Could not find an implementation of the query pattern for source type 'System.ServiceModel.DomainServices.Client.EntityQuery<ChangeManagement.Web.Project>'.  'SelectMany' not found.
>>>
>>>OK  - let's try a join..
>>>            EntityQuery<Project> query = (from p in _Context.Projects
>>>                                          join c in _Context.Change_Requests on p.Project_ID equals c.Project_ID
>>>                                          where c.Subdivision.Equals(SubdivisionID)
>>>                                          select p);
>>>
>>>Error..
>>>Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<ChangeManagement.Web.Project>' to 'System.ServiceModel.DomainServices.Client.EntityQuery<ChangeManagement.Web.Project>'
>>>
>>>What am I missing?? Apparently working with more than one entity changes the query to IEnumerable rather than EntityQuery? 
>>>
>>>How do I get by this?
>>>
>>>
____________________________________

Don't Tread on Me

Overthrow the federal government NOW!
____________________________________
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform