views:

32

answers:

1

I have a class User and a class History. History has 'User' property, and User has 'Histories' property. So there's a database relationship.

But when I create a new User history class and set UserID property, I can't access the 'User' property.

var history = new History { UserID = 1 };
// history.User = null ???

How can I get the user?

+3  A: 

I think you need to create a new User and then set the UserID property:

var history = new History();

history.User = new User { UserID = 1 };
Leniel Macaferi
+1 My own model classes would work this way. Setting the relational key (UserId) will not load the related object (User). Getting the full user object would be a data access operation and not supported in the model.
Marc Tidd
Thanks! Works great now.
Alex