locked
Include Chaining RRS feed

  • Question

  • Hi,

    When using the Include method in a LinqToEntities I notice it can be Chained i.e.

    this.Context.Entity1.Include("Entity2").Include("Entity3")...etc.

    My question is does the second include join Entity3 to Entity1 or Entity 2?

    Also if I slap a .Where at the end does it get applied to Entity1, 2, or 3?

    Thanks

    Thursday, October 15, 2009 12:01 PM

Answers

  • Everything goes back to Entity1. You are including Entity1.Entity2, Entity1.Entity3, etc. The where is also against Entity 1. It is a little more clear if you write it as as a LINQ query:

    from e in this.Context.Entity1.Include("Entity2").Include("Entity3")
    where e.Something = something && e.Entity2.SomethingElse = somethingElse
    select e;

    Thursday, October 15, 2009 12:28 PM
  • The reason you couldn't find any information in the RIA Services documentation is that the Include is part of the Entity Framework, not RIA Services. That is what Casimodo was hinting. LinqToEntitiesDomainService.Context is the Entity Framework context.

    Sunday, October 18, 2009 11:01 PM

All replies

  • Everything goes back to Entity1. You are including Entity1.Entity2, Entity1.Entity3, etc. The where is also against Entity 1. It is a little more clear if you write it as as a LINQ query:

    from e in this.Context.Entity1.Include("Entity2").Include("Entity3")
    where e.Something = something && e.Entity2.SomethingElse = somethingElse
    select e;

    Thursday, October 15, 2009 12:28 PM
  • Thanks Colin, this is a huge help. I've been digging around the .Net RIA Services API documentation and wasn't having any luck finding it.

    Thursday, October 15, 2009 12:36 PM
  •  I've been digging around the .Net RIA Services API documentation and wasn't having any luck finding it
     

    Is this related to RIAS or only to EF?

    Regards,

    Kasimier

    Friday, October 16, 2009 11:59 PM
  • My guess is more specifically related to the LinqToEntitiesDomainService.Context object.

    Sunday, October 18, 2009 10:53 PM
  • The reason you couldn't find any information in the RIA Services documentation is that the Include is part of the Entity Framework, not RIA Services. That is what Casimodo was hinting. LinqToEntitiesDomainService.Context is the Entity Framework context.

    Sunday, October 18, 2009 11:01 PM
  • Got it - thanks.

    Tuesday, October 20, 2009 12:32 PM