1
我正在使用ASP.NET MVC身份并尝试使用代码优先方法创建其他表。我的主表格例如称为Orders
,这是参考AspNetUsers
表(id),并且可以存储每个用户的多个订单。主表中的单独ID将链接到次表中的更多订单详情。实体框架代码优先 - 外键关系
我在努力如何实现两个表之间的关系?如果有人可以请帮助,谢谢
Public Class ApplicationUser
Inherits IdentityUser
Public Overridable Property Orders() As Orders
End Class
Public Class Orders
Public Property Id As String 'Should link to Id in AspNetUsers Table
Public Property TimeandDate As Datetime
Public Property OrderNo As Integer
Public Overridable Property OrderLineDetail() As ICollection(Of OrderLineDetail)
End Class
Public Class OrderLineDetail
Public Property Description As String
Public Property Price As Decimal
End class
Public Class ApplicationDbContext
Inherits IdentityDbContext(Of ApplicationUser)
Public Sub New()
MyBase.New("DefaultConnection", throwIfV1Schema:=False)
End Sub
Public Property Orders() As DbSet(Of Orders)
Public Shared Function Create() As ApplicationDbContext
Return New ApplicationDbContext()
End Function
End Class
为什么难道你不只是[谷歌](http://www.entityframeworktutorial.net/code-first /foreignkey-dataannotations-attribute-in-code-first.aspx)问题的标题?你会发现很多关于数据注释和约定的材料。 –