views:

24

answers:

0

I'm using dynamic query builder methods so I can order by dynamic columns (among other reasons).

I'm joining tables (via calls to Include) where there exists a primary-foreign key relationship. The relationship is actually one-to-one, but EF considers it one-to-many (and that can't even be manually changed directly in the navigation properties of the entities - causes compilation errors).

This is essentially what I'm doing:
dbContext.PrimaryTable.Include("ForeignTable").OrderBy("it.ForeignTable.SomeCol")

This doesn't work because EF considers ForeignTable to be a child collection of PrimaryTable (the error will be "'SomeCol' is not a member of 'Transient.collection[MyModel.ForeignTable]'. To extract a property of a collection element, use a subquery to iterate over the collection"). Adding in a call to Distinct after the Include or other attempts to make it appear as if the child only contains one record doesn't help - it's the navigation properties that still say no, foreign is a child collection.

Is there any way to make EF consider this flattened out?