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 8040245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:50:04+00:00 2026-06-05T03:50:04+00:00

I have table inheritance in database: Ticket{TicketId, TicketTypeId, CreatedBy, Title, Description etc.} UserInfo{TicketId etc.}

  • 0

I have table inheritance in database:

Ticket{TicketId, TicketTypeId, CreatedBy, Title, Description etc.}
UserInfo{TicketId etc.}

TicketId is primary key auto increment. Table UserInfo inherit Ticket table so TicketId in UserInfo is actualy FK for TicketId from Ticket table.
I have model in EF:

public abstract class Ticket
    {
        [Key]
        public int TicketId { get; set; }
        public int TicketTypeId { get; set; }        
        public string Title { get; set; }
        public string Description { get; set; }

        public Guid CreatedBy { get; set; }
        public virtual User User { get; set; }
    } 

public class UserInfo :Ticket
    {
        ...
    }

When I try to insert new UserInfo object to database I write:

User u = context.Users.Find(Membership.GetUser().ProviderUserKey);


            UserInfo o = new UserInfo();
            o.CreatedBy = u.UserId;
            o.Description = "First EF user info to database!";
            o.TicketTypeId = 1;
            o.Title = "First User Info EF";

            context.Tickets.Add(o);
            context.SaveChanges();

But application break on SaveChanges().
I get the following error:

{“Invalid column name ‘User_UserId’.”}
UPDATE
I changed CreatedBy to UserId and I pass this error, but now I have two more issues here:
I save UserInfo to database but there is nothing in UserInfo table. I thought that EF can add this field after save?
This ticket table in database is bound to UserInfo but it’s also bounded to few more tables in database by TicketID but when I try to save object UserInfo I get this error:

{"The INSERT statement conflicted with the FOREIGN KEY 
constraint \"FK_Tickets_Groups\". The conflict occurred in database \"db_Example\", table \"dbo.Groups\", column 'TicketId'.\r\nThe statement has been terminated."}

So to save this I currently removed table references except UserInfo. Can EF handle this situation?

  • 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-06-05T03:50:07+00:00Added an answer on June 5, 2026 at 3:50 am

    I changed CreatedBy to UserId and I pass this error…

    It’s not necessary to change the property name. You just need to tell EF that CreatedBy is the foreign key for the User property (EF doesn’t detect this automatically because the name doesn’t follow the naming conventions):

    [ForeignKey("User")]
    public Guid CreatedBy { get; set; }
    public virtual User User { get; set; }
    

    I save UserInfo to database but there is nothing in UserInfo table. I
    thought that EF can add this field after save?

    If you have the derived entity properties in a separate table you must specify the table name for this entity (Table-Per-Type (TPT) inheritance mapping), otherwise EF will put all derived entities into the same table as the base entity by default (Table-Per-Hierarchy (TPH) inheritance mapping):

    [Table("UserInfo")]
    public class UserInfo : Ticket
    {
        ...
    }
    

    …I get this error…

    It seems that Ticket or UserInfo has a foreign key to a table Groups and that this foreign key property is not set to valid group key value. When you insert the entity the foreign key constraint in the database is violated which results in the exception.

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

Sidebar

Related Questions

I have a legacy database that uses a table per class hierarchy inheritance strategy
I have a rails app that requires multi-table inheritance for which I am using
I have implemented inheritance for two parent classes called Table and Field . Each
I have table Owner in my database where one of the field (System) saved
I have a card-game application which makes use of Single Table Inheritance. I have
I have 2 existing tables in my database. Let's call them Table and Chair
My situation is this: We have a superclass, MyAbstractEntity @Entity @Table(name = MyTable) @Inheritance(strategy
My question is regarding Inheritance modeling in Relational Database Systems. I have canonical data
I'm thinking on new design for database. And I want to use Table-Per-Type inheritance
Using table per type inheritance is it possible to have the same data with

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.