【发布时间】:2011-11-23 12:47:31
【问题描述】:
我正在尝试从数据库中选择标签。我首先使用 EF 代码 4.2、vbnet 和 mvc 3。现在,当我第一次实现该功能时,我发誓它工作正常并且没有检索重复的标签。无论如何,现在它正在提取重复的标签。有人可以看看并告诉我逻辑是否存在缺陷吗?
Using _rdsqlconn As New RDSQLConn
Dim tags
tags = _rdsqlconn.Tags.GroupBy(Function(t) New TagViewModel() With {.TagId = t.TagId, .Tag = t.TagWord}).Select(Function(a) a.Key).ToList()
' Dim tags = _rdsqlconn.Tags.Distinct.ToList ' this didnt work
Return tags
End Using
Public Class TagViewModel
Dim _rdsqlconn As RDSQLConn
Property TagId As Int32
Property Tag As String
ReadOnly Property TagCount As Int32
Get
Using _rdsqlconn As New RDSQLConn
Dim t = _rdsqlconn.Tags.ToList
Return t.Count
End Using
End Get
End Property
ReadOnly Property PostCount As Int32
Get
Using _rdsqlconn As New RDSQLConn
Dim p = _rdsqlconn.Posts.ToList
Return p.Count
End Using
End Get
End Property
【问题讨论】:
标签: vb.net asp.net-mvc-3 entity-framework-4 ef-code-first viewmodel