views:

12

answers:

1

Stupid question maybe, yet still.

public class Foo : EntityObject 
{
    public Bar Bar { get; set; } // navigation property
}
public class Bar : EntityObject
{
    // whatever
}

// code
var myFoo = Foo.Create(); // detached state after this line
var myBar = LoadMyBarFromDatabase(); // Bar comes from DB
myFoo.Bar = myBar; // myFoo.EntityState changes to 'Added'

I do not need myFoo to be added to the database. It must remain detached. I just need it as a fake container of Bar for some time. Nothing else.

Thoughts?

(At the moment I only have a thought to add a new interface IFoo and implement it in FakeFoo class, which is not an EntityObject.

A: 

Well, seems like there is no good solid way to do this. I ended up overriding the SaveChanges method in context and filtering out the trash objects I created. Did not really find anything else since as soon as you add the object to some relationship it is added to the context with the Added state.

Jefim