【发布时间】:2011-11-02 22:01:45
【问题描述】:
我一直在阅读有关如何在 EF 中处理复杂类型的各种博客文章,包括大多数人似乎都链接的 brad wilson 文章。但是我真的不明白。我正在使用 EF 代码优先开发、MVC 和 VB。从我到目前为止所阅读的内容来看,为复杂类型呈现编辑器字段需要自定义对象,对吗?但是我真的不明白我需要在自定义模板中放入什么代码。有人可以为我分解一下,什么代码需要进入自定义模板,以便我可以为 PostTags collection 呈现一个文本框吗?
我的课:
Public Class Post
Inherits EntityBase
<Key()> Property PostId As Integer
<DisplayName("Title")> <Required()> Property PostTitle As String
<UIHint("MultilineText")> <DisplayName("Text")> Property PostText As String
ReadOnly Property PostExcerpt As String
Get
If PostText.Length > 100 Then
Return Helpers.TruncateHelper.TruncateAtWord(PostText, 250)
Else : Return PostText
End If
End Get
End Property
<ScaffoldColumn(False)> Property PostDateCreated As DateTime
<ScaffoldColumn(False)> Property PostDateModified As DateTime?
<ScaffoldColumn(False)> Property PostDatePublished As DateTime?
<DisplayName("Publish?")> Property PostIsPublished As Boolean
<DisplayName("Allow Comments?")> Property CommentsAllowed As Boolean
<ScaffoldColumn(False)> Property CategoryId As Integer?
<UIHint("Text")> <DisplayName("Category")> <Required()> Property PostCategory As String
Property Comments As IList(Of Comment)
'Post has collection of Tags
<DisplayName("Tags (comma separated)")> Overridable Property PostTags As ICollection(Of Tag)
End Class
Public Class Tag
Dim _rdsqlconn As RDSQLConn
<Key()> Property TagId As Int32
Property PostId As Int32
Property TagWord As String
'Overridable property to access Post
Overridable Property Post As Post
End Class
【问题讨论】:
标签: asp.net-mvc vb.net entity-framework ef-code-first