0
我以前用EF Code First From Database生成基於現有數據庫的類。我需要映射這兩個類之間的關係。我懷疑我必須設置外鍵,但不要設置外鍵。如何映射這兩個生成的類之間的關係?
Partial Public Class be_Posts
<Key>
Public Property PostRowID As Integer
Public Property BlogID As Guid
Public Property PostID As Guid
<StringLength(255)>
Public Property Title As String
Public Property Description As String
Public Property PostContent As String
Public Property DateCreated As Date?
Public Property DateModified As Date?
<StringLength(50)>
Public Property Author As String
Public Property IsPublished As Boolean?
Public Property IsCommentEnabled As Boolean?
Public Property Raters As Integer?
Public Property Rating As Single?
<StringLength(255)>
Public Property Slug As String
Public Property IsDeleted As Boolean
End Class
Partial Public Class be_PostTag
<Key>
Public Property PostTagID As Integer
Public Property BlogID As Guid
Public Property PostID As Guid
Public Property PostRowID As Integer
<StringLength(50)>
Public Property Tag As String
End Class
謝謝你的回答。但它沒有工作。我將 Public Property PostRow添加爲be_Posts爲be_PostTag,並在be_Posts中將添加到PostRowID。然後拋出錯誤該屬性不能配置爲導航屬性。該屬性必須是有效的實體類型。 –
@AshokPadmanabhan這裏有一篇類似的文章,其答案就是提供了很好的信息和例子,你能否看到這些例子是否爲你的新問題提供了答案。再次抱歉,這些例子是在C#中。 http://stackoverflow.com/questions/20202578/relationships-in-entity-framework-code-first – Madullah