簡體   English   中英

為什么我會得到“最好的重載列表”<delegationinformation> 集合初始值設定項的 add 方法有一些無效參數”</delegationinformation>

[英]Why am I getting “the best overloaded List<DelegationInformation> add method for the collection initializer has some invalid arguments”

我想返回delInfo變量和其中的數據。 但我不明白它到底出了什么問題?

我收到錯誤

集合初始化器的最佳重載列表添加方法有一些無效的 arguments

這是我的代碼:

public List<DelegationInformation> GetDelegations(string profileUid, List<int> userPrivilegeIds)
{
    using (var context = GetDBContext())
    {
        var delInfo =
            (
                from delegation in context.vw_Delegations
                where delegation.Delegator == profileUid && userPrivilegeIds.Contains(delegation.AccessPrivilegeID)
                select new DelegationInformation()
                {
                    id = delegation.DelegationID,
                    DelegationId = delegation.DelegationID,
                    AccessPrivilegeId = delegation.AccessPrivilegeID,
                    AccessPrivilegeKey = delegation.AccessPrivilegeKey,
                    AccessPrivilegeName = delegation.AccessPrivilegeName,
                    Enabled = delegation.Status,
                    IsPermanent = delegation.isPermanent.HasValue ? delegation.isPermanent.Value : false,
                    Delegatee = delegation.Delegatee,
                    DelegateeFirstName = delegation.DelegateeFirstName,
                    DelegateeLastName = delegation.DelegateeLastName,
                    Delegator = delegation.Delegator,
                    DelegatorFirstName = delegation.DelegatorFirstName,
                    DelegatorLastName = delegation.DelegatorLastName,
                    StartDate = delegation.StartDate,
                    EndDate = delegation.EndDate,
                    ChangedBy = delegation.ChangedBy,
                    ChangedOn = delegation.ChangedOn,
                }
            ).ToList();

        foreach (var item in delInfo)
        {
            item.DelegateeFullName = ARMCommon.GetProfileDisplayName(item.Delegatee);
            item.DelegatorFullName = ARMCommon.GetProfileDisplayName(item.Delegator);
        }

        return new List<DelegationInformation>
        {
           delInfo
        };
    }
}

只需返回 delInfo,因為它已經列出

return delInfo;
                    

回報應該是

return delInfo;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM