none
How to apply condition on one to many relationship in entity framwork RRS feed

  • Question

  • I have two object with one to many relation ship. I want to apply condition on second collections of object. Below is my code.

    DateTime date = DateTime.Now.AddDays(-15); IQueryable applicant = from app in productionEntities.CDCPortalApplicant.Include("CDCPortalUnit") where app.FirstName == firstName && app.LastName == lastName && app.EmailAddress == emailAddress && app.Created > date && app.CDCPortalUnit.PropertyId == propertyId select app;

    Here CDCPortalUnit have more the one object for CDCPortalApplicant object app.CDCPortalUnit.PropertyId == propertyId

    Monday, May 5, 2014 9:19 AM

Answers

  • Hi Krish1983;

    See if this corrects the error you are getting.

    IQueryable applicant = from app in productionEntities.CDCPortalApplicant
                                                         .Include("CDCPortalUnit") 
                           where app.FirstName == firstName 
                              && app.LastName == lastName 
                              && app.EmailAddress == emailAddress 
                              && app.Created > date 
                              && app.CDCPortalUnit.Any(p => p.PropertyId == propertyId) 
                           select app;



    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, May 5, 2014 4:16 PM