开发者

ASP.NET MVC - Can't access a parent class in a database relationship (LINQ TO SQL)

开发者 https://www.devze.com 2023-01-01 18:32 出处:网络
I have a class User and a 开发者_Python百科class History. History has \'User\' property, and User has \'Histories\' property. So there\'s a database relationship.

I have a class User and a 开发者_Python百科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?


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 };
0

精彩评论

暂无评论...
验证码 换一张
取 消