Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Linq to entities - what is wrong here.
Message
General information
Forum:
ASP.NET
Category:
Silverlight
Miscellaneous
Thread ID:
01524523
Message ID:
01524589
Views:
46
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?




>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?
>>
>>
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform