I am using the entity framework. I have workers table:
Worker(workerId, name, statusId)
I have POCO for worker with navigation property:
class Worker {
public virtual long workerId {get;set;}
public virtual string name {get;set;}
public virtual long statusId {get;set;}
public virtual Status status {get;set;}
}
In order to insert worker, I fill the name, the status id and even the status (the navigation property) with the relevant values.
But instead of inserting only the worker, it insert also the status and creates a new row for the same status (even though I fill the statusId and the id inside the status object).
Why does it inserts the record?..
In order to insert, set only statusId and leave status as null.
This will make the insertion without duplicate associations.
If you fill the status object, the framework entity considers it as a new object (or row).