Wednesday, 15 February 2012

EF 5 - Unable to determine if an entity is attached -


I am trying to determine if an EF5 unit is attached as follows:

This method is called first:

  Public Bull IActed (Object Entity) {EntityKey entityKey = GetEntityKey (unit); If (unit == empty) false return; Back to IATACHED (This. SOBJACTTECT (), entity); }   

which is called this method:

  Public EntityKey GetEntityKey {Object Entity} {ObjectStateEntry ObjectStateEntry; If (empty !: entity & amp; this. Object contact (). ObjectStateManager.TryGetObjectStateEntry (entity, outside objectstate entry)) {Object Object unbreakable. AntityKey; } Return tap; }   

If the IsAttached () method returns false, then this method is called:

  var attachedin = reference .set & lt; Tentity & gt; (). Attach (unit);   

The problem I am having is that isAttached () method always goes wrong, because GetEntityKey () still When the object is already attached to IOW, even when a unit is attached, then I can not get the key of the unit, due to which the whole thing fails, can anyone see what I am doing ?

I am using EF5, not the first code.

You do not need a majority of that code ... just

 < Code> use (reference .entry (entity) .set == EntityState.Detached)    

No comments:

Post a Comment