'无法将类型'System.Guid'转换为类型'System.Object'。 LINQ to Entities 仅支持转换 EDM 基元或枚举类型。'

问题描述 投票:0回答:1

尝试使用 linq 从我的数据库检索信息,但它不起作用。当我执行代码时,它抛出异常“'无法将类型'System.Guid'转换为类型'System.Object'。LINQ to Entities仅支持转换EDM基元或枚举类型。”

Public Class HomeTree
    Inherits ApplicationFolders

    Private _CanList As Boolean
    Public Property CanList() As Boolean
        Get
            Return _CanList
        End Get
        Set(value As Boolean)
            _CanList = value
        End Set
    End Property

    Private _CanEdit As Boolean
    Public Property CanEdit() As Boolean
        Get
            Return _CanEdit
        End Get
        Set(value As Boolean)
            _CanEdit = value
        End Set
    End Property

    Private _CanAdd As Boolean
    Public Property CanAdd() As Boolean
        Get
            Return _CanAdd
        End Get
        Set(value As Boolean)
            _CanAdd = value
        End Set
    End Property

    Private _CanDelete As Boolean
    Public Property CanDelete() As Boolean
        Get
            Return _CanDelete
        End Get
        Set(value As Boolean)
            _CanDelete = value
        End Set
    End Property
    Public Sub New()

    End Sub
End Class

检索数据

Dim GBItems As List(Of HomeTree) = (From t In db.ApplicationFolders
                                            Join r In db.AppFolderRoleConfig On {t.AppFolderId, isLoggedInUser.ID_Role} Equals {r.AppFolderID, r.RoleID}
                                            Where t.ParentID = 0 AndAlso t.TypeID = 1 Select New HomeTree With {
                                                                                          .ID_Key = t.ID_Key,
                                                                                          .AppFolderId = t.AppFolderId,
                                                                                          .Name = t.Name,
                                                                                          .Active = t.Active,
                                                                                          .Description = t.Description,
                                                                                          .ParentID = t.ParentID,
                                                                                          .TypeID = t.TypeID,
                                                                                          .CanAdd = r.CanAdd,
                                                                                          .CanDelete = r.CanDelete,
                                                                                          .CanEdit = r.CanEdit,
                                                                                          .CanList = r.CanList
                                                                                          }).ToList()

我尝试用谷歌搜索我的问题,但我无法弄清楚。

vb.net winforms linq
1个回答
0
投票

尝试这个查询示例。因为我不知道你的数据库结构(未提供)和我自己假设的数据示例。 我想这就是你要找的

New With {Key.a = af.AppfolderiD.Value, Key.v = isLoggedInUser_ID_Role}

代码

    Dim isLoggedInUser_ID_Role As Integer = 1

    Dim GBItems = (
        From af In ApplicationFolders
        Join ar In AppFolderRoleConfig On
            New With {Key.a = af.AppfolderiD.Value, Key.v = isLoggedInUser_ID_Role} Equals 
            New With {Key.a = ar.AppFolderID.Value, Key.v = ar.RoleID.Value} 
    Where af.ParentID = 0 AndAlso af.TypeID = 1 
    Select New HomeTree() With {
        .ID_Key = af.ID_Key,
        .AppFolderId = af.AppfolderiD,
        .Name = af.Name '...
    })
    GBItems.Dump()
© www.soinside.com 2019 - 2024. All rights reserved.