【问题标题】:Group By syntax does not seem to be working nowGroup By 语法现在似乎不起作用
【发布时间】: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


    【解决方案1】:

    已修复。取出 .TagId 部分。现在它不再重复标签了

    【讨论】:

      猜你喜欢
      • 2014-11-17
      • 2012-01-30
      • 2015-09-23
      • 2023-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多