Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5952085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:37:51+00:00 2026-05-22T17:37:51+00:00

I have a model with TPT inheritance. Location ( abstract ) Street ( derived

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:37:52+00:00Added an answer on May 22, 2026 at 5:37 pm

    Okay, i’ve found one workaround.

    And that is to flip the FK around.

    So instead of:

    1 Street -> 0..1 GoogleStreetView

    Which is correct, i now have:

    * Street -> **0..1 GoogleStreetView

    So now Street has a nullable FK pointing to GoogleStreetView.

    And that works and acts fine from a code perspective, but from a database perspective this is totally wrong, as with this lack of referential integrity, one particular GoogleStreetView record could point to multiple Street records, which doesn’t make any sense.

    But this looks like the only proper workaround.

    It just seems like EF does not support 1 – 0..1 associations backed by a PK/FK combo.

    Unacceptable if you ask me. If they knew this was a bug in EF 4.0, why didn’t they fix it in 4.1???

    EDIT

    Also the above workaround will work, not happy with breaking the referential integrity in the conceptual side.

    So i’ve decided to not map this entity at all and go fetch it from the DB via a stored procedure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model, Thing, that has a has_many with ThingPhoto, using Paperclip to
Let's assume I have a model called product. Let's assume that product has three
I have model called User with a has_many relationship to UserFilter . UserFilter has
I have model Foo which has field bar. The bar field should be unique,
I have model People and model Group, People has field of type Group. How
I have model Article it has field title with some text that may contain
I have a model that already has a couple dozen of columns that will
I have a model that has several properties. The properties can be primitive (String)
I have a Model that has several properties. When I submit a form, I
I have model Person or say Profile and this class Person has a genericRelationship

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.