0

I've created two entities which are related to each other by joining using three columns, both are views on the database. For the Travel I have the Id, FromCityId and ToCityId, for TravelCost I have the TravelId, FromCityId and ToCityId. The fluent mapping is as below

TravelEntityConfiguration class:

HasMany(x => x.Amounts)
    .WithRequired()
    .HasForeignKey(x => new
    {
        x.TravelId,
        x.FromCityId,
        x.ToCityId
    });

and for the travel cost its

TravelCostEntityConfiguration

HasRequired(x => x.Travel)
    .WithMany()
    .HasForeignKey(x => new
    {
        x.TravelId,
        x.FromCityId,
        x.ToCityId
    });

When i query these entities and include the navigation property

context.Set<Table>().Include(x => x.TravelCost)....

For each result only the first of the child collection is loaded. I checked the query generated, even the query is correct it returns the full set with all the children and the join is correctly. What am i missing here. Need some help no clue for the moment. basically i suspect the mapping is not correct but didn't found out the problem yet.

enter image description here

enter image description here

CodeNotFound
  • 22,153
  • 10
  • 68
  • 69
ivi.hamiti
  • 552
  • 1
  • 4
  • 7

1 Answers1

1

Thank you Asad, you lighted up my problem. The problem was with the Id of the TravelCost view which were generated on the fly and ended up to be the same so EF thinks it is the same record, the mapping was totally correct.

Community
  • 1
  • 1
ivi.hamiti
  • 552
  • 1
  • 4
  • 7