【问题标题】:Delegate "System.Func<Testproj.pInfo,int,bool> does not take 1 argument"委托“System.Func<Testproj.pInfo,int,bool> 不接受 1 个参数”
【发布时间】:2013-04-22 10:06:20
【问题描述】:
    MembershipUser userobj = Membership.GetUser();
        Guid currentuserid = (Guid)userobj.ProviderUserKey;
        List<pInfo> pobj = new List<pInfo>();
        pobj = (from pid in db.pInfoes.Where(c => c.UserIdentity == currentuserid)
                orderby pid.pId descending
                select pid).ToList();
        return View(pobj);


   (c => c.UserIdentity == currentuserid) : Error -- Delegate   "System.Func<Testproj.pInfo,int,bool> does not take 1 argument"

我在 stak-overflow 上遇到了许多类似的问题,但无法解决。需要一些关于代表的指导......

【问题讨论】:

    标签: asp.net asp.net-mvc-3 entity-framework delegates


    【解决方案1】:

    抱歉,我的问题的描述具有误导性。问题不是委托代码,而是我传递给实体框架查询的参数类型。由于 UserIdentity 是 Unique-identifier 类型,并且 pInfo 在 edmx 文件中有 StoreGeneratedPattern="none" 用于这种类型。 我不得不在 edmx 文件中将 StoreGeneratedPattern 更改为身份类型,它工作正常。 下面的帖子和上面的一些 cmets 帮助我确定了这个问题。 感谢大家的关心和宝贵的时间。 http://leedumond.com/blog/using-a-guid-as-an-entitykey-in-entity-framework-4/

    【讨论】:

      【解决方案2】:

      UserIdentity 是否为整数类型,如果不是,则需要UserIdentity.Id=currentuserid

      【讨论】:

        【解决方案3】:

        您的函数c =&gt; c.UserIdentity == currentuserid 的参数与所需的System.Func&lt;Testproj.pInfo,int,bool&gt; 不匹配。你也需要一个int 参数。我假设你已经期望cTestproj.pInfo,所以你只需要为int 添加一个参数。基金回报类型为bool。试试:

        .Where((c, i) => c.UserIdentity == currentuserid)
        

        【讨论】:

        • 委托 "System.Func 不接受 2 个参数"
        • 嗯,与您最初的代码匹配。如果您将(c, i) =&gt; 改回c =&gt;,原始错误消息(问题中的那个)会回来吗?
        • 是的,它确实回来了..System.Func 不接受 1 个参数
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-07
        • 1970-01-01
        相关资源
        最近更新 更多