views:

45

answers:

2

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
A: 

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_s
+3  A: 

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.

Craig Stuntz
Thanks for your support, Craig!! Maybe all those downvoters will reconsider punishing my post.....
marc_s
That absolutely worked! Thanks!!
Daniel Magliola