Assuming I have a row in the database with a specific id which I know (in my sample below - a symbol with Id = 5), can I create an EntityObject which can be attached to another entity without the need to load it from the database (same scenario is applicable to "DeleteObject" as well, if you think about it...)?
I've tried the following:
UserSpread spread = UserSpread.CreateUserSpread(5, 500000, 1.1m, 1.5m);
EntityKey symbolKey = new EntityKey("Entities.SymbolSet", "Id", 5);
Symbol symbol = new Symbol();
symbol.EntityKey = symbolKey;
// dealingEntities.Attach(symbol);
spread.Symbol = symbol;
Entities.AddToSpreadSet(spread);
I get the following exception on the "AddToSpreadSet()" method:
"The object cannot be added to the ObjectStateManager because it already has an EntityKey. Use ObjectContext.Attach to attach an object that has an existing key."
If I try to attach the symbol before assigning it to the spread (commented line), I get the following on the "SaveChanges()" method:
"The object cannot be attached because the value of a property that is a part of the EntityKey does not match the corresponding value in the EntityKey."
Any ideas?
Thanks,
Nir