繁体   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