I have this code for example for an event handler
public void ONDataArrived ( string data )
{
//do some processing and save it to DB using EF
ctx.Add ( x ) ;
ctx.SaveChanges () ;
}
Is there any chance that EF may error if this event fired a couple of times in the same time ?
thanks
EF 5 can work in several different models, depending on how you want to use it. There are templates for using context-tracked entities, self-tracked entities, or POCOs. For your case, I would recommend not keeping your context object around. Self-tracking entities are probably what you’re looking for – they store internally all of the information needed to update the database instead of relying on the context to track it.
If you go the self-tracked route, then your OnDataArrived method would just create a new context object and update the entity, which would also address the threading issue mentioned by weismat.