I am trying to update the entity that has some columns with foreign keys. Everything seems to work fine but during first time assignment, it takes more than 1 minute but if I execute the same action again , it comes immediately.
Code Snippet :
public bool UpdateStatus(DetailDataModel DetailDataModel)
{
Details updateStatus = (from d in UnitOfWork.Details
where d.Id == DetailDataModel.Id
select d).FirstOrDefault();
updateStatus.StatusId = DetailDataModel.StatusId;
UnitOfWork.Commit();
return true;
}
Below is the culprit line :
updateStatus.StatusId = updateStatus.StatusId;
I cannot find the problem but when try to update other columns of the same entity, it works fine and the problem is only with Foreignkey columns. Is there any limitation for association with Entity framework.
Please suggest your thoughts on it, Thanks in Advance.
I guess you are using POCO T4 Generator and you have lazy loading enabled because in such case the delay can be easily explained – fixup methods in generated POCO classes will cause lazy loading of Status entity and in turn lazy loading of all its related Details.
If you don’t need lazy loading for this operation try to turn it off in your context otherwise you will have remove circular reference from your entity model (
Statuswill not have navigation property toDetails) or modify T4 template and remove those fixup calls.