I have 2 tables Work and schedule
Job
JobId - int, PK, Identity
ScheduleId - int, FK
Title - varchar
Description - varchar
schedule
ScheduleId - int, PK, Identity
Name - varchar
There is one relationship with the cascade on deletion.
When I create an Entity model, the created Jobs model removes the ScheduleId field.
The problem is that I cannot add a new task with the specified ScheduleId!
Job job = new Job();
job.title= "blabla";
job.description="xyz";
job.scheduleId=1
if (job.EntityState == EntityState.Detached)
{
myContext.AddToJobs(job);
}
myContext.SaveChanges();
Note. I have a row in the schedule table with scheduleId = 1.
source
share