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

  • SEARCH
  • Home
  • 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 6031087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:07:55+00:00 2026-05-23T05:07:55+00:00

I have a table with an int PK, one NOT NULL field, and two

  • 0

I have a table with an int PK, one NOT NULL field, and two NULL string fields.

When I go and set up a TPH-style design in EF, I set it up this way:

The top level type only has the PK and the NOT NULL field.

The first level checks the first nullable field as a discriminator. The not null resulting type is abstract. I map the field accordingly.

I do this again for the second field, again mapping where not null. I set nullable = false on the fields I map.

<EntitySetMapping Name="Items">
        <EntityTypeMapping TypeName="IsTypeOf(Model1.Item)">
          <MappingFragment StoreEntitySet="Items">
            <ScalarProperty Name="ID" ColumnName="ID" />
            <ScalarProperty Name="OtherID" ColumnName="OtherID" />
          </MappingFragment>
        </EntityTypeMapping>
        <EntityTypeMapping TypeName="IsTypeOf(Model1.BothNullItem)">
          <MappingFragment StoreEntitySet="Items">
            <ScalarProperty Name="ID" ColumnName="ID" />
            <Condition ColumnName="FirstNullField" IsNull="true" />
            <Condition ColumnName="NullField2" IsNull="true" />
          </MappingFragment>
        </EntityTypeMapping>
        <EntityTypeMapping TypeName="IsTypeOf(Model1.FirstFieldNull)">
          <MappingFragment StoreEntitySet="Items">
            <ScalarProperty Name="ID" ColumnName="ID" />
            <ScalarProperty Name=FirstNullField" ColumnName="FirstNullField" />
            <Condition ColumnName="FirstNullField" IsNull="false" />
          </MappingFragment>
        </EntityTypeMapping>
        <EntityTypeMapping TypeName="IsTypeOf(Model1.NotNullSubItem1)">
          <MappingFragment StoreEntitySet="Items">
            <ScalarProperty Name="ID" ColumnName="ID" />
            <Condition ColumnName="NullField2" IsNull="true" />
          </MappingFragment>
        </EntityTypeMapping>
        <EntityTypeMapping TypeName="IsTypeOf(Model1.NotNullSubItem2)">
          <MappingFragment StoreEntitySet="Items">
            <ScalarProperty Name="ID" ColumnName="ID" />
             <ScalarProperty Name="NullField2" ColumnName="NullField2" />
             <Condition ColumnName="NullField2" IsNull="false" />
          </MappingFragment>
        </EntityTypeMapping>
</EntitySetMapping>

I’m getting “two entities with different keys are mapped to the same row.”

I am thinking it’s because maybe the first item’s not null attribute is not getting inherited by the children.

I’ve created a third type to try to take care of the case of NullField1 being null and NullField2 not being null (which will not happen in my DB, I have a constraint), but even if I added it it doesn’t work.

Explicitly adding the not null condition on either of the 2 sub children requires me to map the column, which still doesn’t work even if I map it to some extraneous property.

None of the combinations of conditions for “BothNullItem” works either.

Any ideas?

  • 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-23T05:07:56+00:00Added an answer on May 23, 2026 at 5:07 am

    Welp, I ended up giving up on trying to get discriminator columns to propagate through inheritance so I created 3 views, one top level, one for null field1 and not null field one, and then on not null field one, I make field2 the discriminator column in EF. This sounds like a crappy answer to my problem so I’d like to hear from someone in the know what the deal is. Buehler?

    UPDATE: FIXED! Going off of the horizontal partitioning concept in one of the articles I found on msdn (http://msdn.microsoft.com/en-us/library/cc716779.aspx)I went in and manually added the conditions in the msl. It looks like you can’t have this work automatically from the designer. For those of you wondering, open the edmx in the xml editer and go down and look at the conditions elements of your mappings. Add in extra conditions where needed (apparently conditions don’t inherit from parent entities so you have to manually add them to the children) and compile!

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

Sidebar

Related Questions

I have this table CREATE TABLE `codes` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
I have this table: CREATE TABLE `test` ( `ID` int(11) NOT NULL auto_increment, `text`
I have this table: CREATE TABLE `point` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `siteid`
I have two tables: CREATE TABLE 'sales_sheet' ( `_id` int(11) NOT NULL AUTO_INCREMENT, `_typed_by`
I have a table like this one CREATE TABLE MyTable ( [MyTableID] [int] NOT
I have two tables: CREATE TABLE [dbo].[Context] ( [Identity] int IDENTITY (1, 1) NOT
i have table and i tried to add `id` int(11) NOT NULL auto_increment, to
Suppose I have these two tables: Invoice ------- iInvoiceID int PK not null dtCompleted
I have an ai_order table. CREATE TABLE `ai_order`( `id` INT(11) NOT NULL AUTO_INCREMENT, `product_id`
I have a table like this below, Field Type Collation Attributes Null Default cde_id

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.