How can I change a primary key value in one-one relationship?
Hi
I'm using entity framework 4 as business layer. I've two table in one-one relationship: Users <开发者_C百科---> Employees Employees table have the same primary key as Users table, so when I add record to Users i have to add one to Employees with the same PK value...and that throws an exception. Actually I'm doing this using entity framework :// after adding new Users entity, I add new Employee item to it
newUserEntity.Employee = newEmployeeEntity;
What should I do to be able to insert the PK manually ?
Thanks in advance
There are a number of ways to fix this.
The first one is why do you have two tables. Could you instead have a single table but have a User and an Employee view of that table.
The second is that if you have two tables, why do both of them have an auto generated primary key. You could generate the key in the program (or get it from a key table) and then just insert the key values in the tables.
精彩评论