【发布时间】:2014-08-18 23:57:01
【问题描述】:
我无法弄清楚我在这里做错了什么。 MVC 新手和 Entity 新手,所以我知道这阻碍了我。每当我调用 AuthUser 时,AuthRole 总是什么都不是,所以我最终会执行以下操作:
authuser.AuthRole = db.AuthRoleSet.Find(2) 'AuthRoleID of 2 = User
这对我来说只是感觉很笨拙。如何让我的属性真正获得用户的角色?
这是我的班级结构: 公共类 AuthUser '类全局变量 将数据库调暗为新的 AuthUserContext
'Properties
Public Property AuthUserID() As Integer
<Required()> _
<Display(Name:="User Name")> _
<DomainUserValidation()> _
Public Property UserName() As String
<Display(Name:="Current Role")> _
Public Property AuthRole As AuthRole
End Class
Public Class AuthRole
Public Property AuthRoleID() As Integer
<Required()> _
<Display(Name:="Role Name")> _
Public Property RoleName() As String
<Required()> _
<Display(Name:="Is Administrator")> _
Public Property isAdministrator() As Boolean
<Required()> _
<Display(Name:="Is Active")> _
Public Property isActive() As Boolean
<Required()> _
Public Property AuthUser As ICollection(Of AuthUser)
End Class
Public Class AuthUserContext
Inherits DbContext
Public Property AuthUserSet() As DbSet(Of AuthUser)
Public Property AuthRoleSet() As DbSet(Of AuthRole)
End Class
【问题讨论】:
标签: asp.net-mvc vb.net asp.net-mvc-4 entity code-first