I have a model with TPT inheritance.
- Location (abstract)
- Street (derived from Location)
- GoogleStreetView (
1
Street ->0..1
GoogleStreetView)
Each of the above has it's own table.
All was working fine until i added the "GoogleStreetView" table (which is backed by a PK/FK to Street).
When i try and do this:
var street = _locationRepository
.Find()
.OfType<Street>()
.Include(x => x.GoogleStreetView)
.SingleOrDefault(x => x.LocationId == 1);
I get the error:
The ResultType of the specified expression is not compatible with the required type. The expression ResultType is 'Transient.reference[xxxx.Repositories.SqlServer.Location]' but the required type is 'Transient.reference[xxxx.Repositories.SqlServer.Street]'. Parameter name: arguments[0]
What the...?
Then i found this thread which basically states this is a bug with EF 4 (and EF 4.1 RTM, by the looks of it).
I don't understand the workaround of "use an independant association, without a backing FK".
I use the Repository / UoW pattern, so my LocationRepository only has access to ObjectSet<Location>
. So i can't do explicit joins in LINQ queries.
At this stage, it's looking like i'll have to not map this table at all, and go fetch it from the database using a stored procedure. Sigh.
Can anyone shed some light on this, and offer a solution?