7

in my current project I'm using code first approach.

I have a type called Task which is part of the model. I also have BackgroundTask derived from Task and UserAccountTask derived from BackgroundTask.

When I simply try to create an object of type Task and add it to my task repository, I get a DbUpdateException as soon as I try to save the changes to the db. Its inner exception states:

"Invalid column name 'UserAccount_UserId'.\r\nInvalid column name 'UserAccount_Lastname'.\r\nInvalid column name 'UserAccount_Firstname'.\r\nInvalid column name 'UserAccount_Fullname'.\r\nInvalid column name 'UserAccount_Password'.\r\nInvalid column name 'UserAccount_Title'[...]"

UserAccount is another type and a property of UserAccountTask (UserId, Lastname etc. are properties of UserAccount).

I hope my description of the problem isn't too messed up :-/ I just want EF to ignore the fact that Task is the base class for some other type because IMHO it doesn't matter at that time.

Thanks in advance, Kevin

1 Answer 1

18

Try to use this in your derived context:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    base.OnModelCreating(modelBuilder);
    modelBuilder.Ignore<UserAccountTask>();
    modelBuilder.Ignore<BackgroundTask>();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.