我在我的EF图表中看到了很多这些导航属性,但不确定它们到底是用来做什么的。就像我在很多表中看到的那样,我有aspnet_Users属性。
这些是做什么用的?它们对joins有帮助吗?不然呢?
Error 2
Error 3007: Problem in Mapping Fragments starting at lines 1201, 1423:
Non-Primary-Key column(s) [Field2] are being mapped in both fragments
to different conceptual side properties - data inconsistency is possible
because the corresponding conceptual side properties can be independently
modified.发布于 2009-08-11 19:06:06
导航属性允许您从一个实体导航到一个“连接”的实体。
例如,如果您的用户连接到某个角色,您可以使用“角色”导航来读取和检查与该用户关联的角色。
编辑:
如果你想用LINQ- to -Entities加载用户,同时查看它的"Role“导航属性,你必须在你的LINQ查询中显式地包含"Role”实体- EF NOT自动为你加载这些导航属性。
// load user no. 4 from database
User myUser = from u in Users.Include("Role")
where u.ID = 4
select u;
// look at the role the user has
string roleName = myUser.Role.Name;或者:
// load user no. 4 from database
User myUser = from u in Users
where u.ID = 4
select u;
// check to see if RoleReference is loaded, and if not, load it
if(!myUser.RoleReference.IsLoaded)
{
myUser.RoleReference.Load();
// now, the myUser.Role navigation property should be loaded and available
}
// look at the role the user has
string roleName = myUser.Role.Name;它基本上等同于数据库中的外键关系--两个对象之间的连接。它基本上“隐藏”或解决了两个表(或EF中的两个实体)之间的连接。
Marc
https://stackoverflow.com/questions/1262307
复制相似问题