When I have an entity object, how do I set the relationship without having the object, just by having the id? Something like:
Post.BlogId = 42
When I have an entity object, how do I set the relationship without having the object, just by having the id? Something like:
Post.BlogId = 42
You wait until Entity Framework v4 ships with .NET 4.0 :-)
This is one of the major features that EF4 will bring - the ability to set a relationship/association by using just the foreign key ID.
See:
Marc is right for EF 4 (+1). But for EF 1 you can do:
Post.BlogReference.EntityKey =
new EntityKey("MyEntities.Blogs", "BlogId", 42);
Replace the strings with whatever is right for your model.