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