Suppose I have 2 tables:
Person(pid, ....) //Pid is identify colum as primary key
Student(pid, Student_No,...) //pid is foreign key from Person, pid is a primary key too.
Then use EF to generate entity model. THen try to insert new data with following code:
Person person = new Person()
{ FirstName = "FirstName", LastName= "LastName", ... };
Student student = new Student(){Student_No="001", ...};
Student.Person = person;
mycontext.Students.AddObject(student);
mycontext.SaveChanges();
Then I get error as: A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: 'pid'.
How to fix it?
Modify the code like:
Person person = new Person(){ FirstName = "FirstName", LastName= "LastName", ... };
mycontext.People.AddObject(person);
mycontext.SaveChanges();
Student student = new Student(){Student_No="001", Person = person, ...};
// or Student student = new Student(){Student_No="001", pid= person.pid, ...};
mycontext.Students.AddObject(student);
mycontext.SaveChanges();
then I was able to insert for person, but for Student, still get same error. Check Student entity pid property in EDM: storegeneratedPatteren = None. Quite confused.