Group By语法现在似乎不起作用

时间:2011-11-23 12:47:32

标签: vb.net asp.net-mvc-3 entity-framework-4 ef-code-first viewmodel

我正在尝试从数据库中选择标签。我正在使用EF Code第一个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

1 个答案:

答案 0 :(得分:1)

固定。拿出.RigId部分。现在它不会返回重复的标签