c# - Entity Framework Code First - Cannot insert duplicate key in object 'db' -


I'm using the new EF code in my project first, and I'm getting a weird error, my mode is :

  abstract class members {public virtual member of public; ... some other stuff} Class users: Members {public virtual string name; ... some other props are not defined by a new key} Category MyDbContext {public DbSet   

The result of deployment on SQL Server is fine, I have a member table and a user table (TPC). Now in my main I have the following code:

  Fixed main () {User X, Y; (MyDbContext ctx = new MyDbContext ()) using {x = ctx.Users.Create (); Y = ctx.Users.Create (); X.Name = "SomeUser"; Y.Name = "SomeUser2"; Ctx.SaveChanges (); }}   

I save changes:

"Unchecked exception: System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries See Internal Exceptions for Hui De Tuq. ---> System.Data.UpdateException: An error occurred while updating the entries. See internal exceptions for details. ---> System.Data.SqlClient SqlException: Violation of primary key 'PK_ user _0CF04B1821B6055D'. Duplicate in item 'dbo.users' The key can not be inserted. "

By default, MemberId is identical, so I'm just not seeing what's happening here, I tried to create an example with new ones And attach them in context, but the error was similar, any thoughts?

EDIT: Remember to tell that the member is an abstract class that is competing.

I tested it and the table of derivatives generated in TPC (table per concrete type) PK has not been defined as an identity in EF 4.1 in R.C.

Comments

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -