【发布时间】:2012-09-22 16:23:38
【问题描述】:
我有一个用户表:
Users:
+ID
+Username
+...
我想使用myDBContext.Users.Find(Username) 来查找用户。
在我目前的情况下,我不能使用他的 ID。
我必须使用完整的 LINQ 查询吗?例如
var user = from users in myDBContext.Users.Find(Username)
where users.Username == username
select users
我还尝试将用户名定义为我的 edmx 中的主键,但这导致了以下错误:
主要角色用户引用的属性必须完全正确 与 EntityType 的键相同 CamelotShiftManagementModel.User 中的 Principal Role 引用 关系的关系约束 CamelotShiftManagementModel.AssociationUserFK1。确保所有关键 属性在主体中指定 角色。 C:\Code\CamelotShiftManagement\CamelotShiftManagement\Models\CamelotDB.edmx 278 11 CamelotShiftManagement
【问题讨论】:
标签: asp.net-mvc linq entity-framework