sql server - New object in Entity Framework - problems with primary key -


In my database I have a vehicle table with a primary key, I have a new Vehicle using the item

  new vehicle ();  

and appropriately updating the properties of the vehicle

When I

  Junky's Contax Wheels. I try to object;  

The table for the first time has been updated successfully and the primary key is 0. On all subsequent occasions, I get an error by saying that the key is not unique

the primary key constraint 'VEHICLES_PK' can not be included in the violation object 'dbo.Vehicles' in the duplicate key is. \ R \ nThe statement has been terminated.

(possibly because the primary key still determined by EF 0 )

I understand that the EF wisely excludes the primary key Works, why is this happening ??

You have two options:

  • In that case, SQL Server will automatically assign unique and individual numbers, and EF will be OK with that
  • to INT identity (1,1) Take care, eg You need to find your app to come up with unique vehicle ID numbers in your vehicle.

From the box there is nothing for the EF to distribute the unique numbers for the primary key, primarily - if you thought it was a misconception.

Mark


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -