使用"其中":不能转换拉姆达EX pression键入“布尔”布尔、拉姆、QUOT、pression

2023-09-04 04:10:25 作者:對迩、心淡ろ

我有如图below.I我收到在以下错误的实体框架code状态。

  

无法将拉姆达EX pression键入布尔,因为它不是一个委托类型

如何克服这个问题?什么是此错误的原因是什么?

 静态无效的主要(字串[] args)
    {

        ClubCreation();
        名单<俱乐部GT; selectedClubs = GetClubs(club1);

    }

    公共静态无效ClubCreation()
    {

        字符串的ConnectionString =数据源=;初始目录= NerdDinners;集成安全性= TRUE;连接超时= 30;
        使用(VAR DB =新NerdDinners(的ConnectionString))
        {

            俱乐部club1 =新东家();
            club1.ClubName =club1;

            俱乐部club2 =新东家();
            club2.ClubName =club2;

            俱乐部club3 =新东家();
            club3.ClubName =club3;

            db.Clubs.Add(club1);
            db.Clubs.Add(club2);
            db.Clubs.Add(club3);

            INT recordsAffected = db.SaveChanges();


        }
    }

    公共静态列表<俱乐部GT; GetClubs(字符串clubName)
    {
        字符串的ConnectionString =数据源=;初始目录= NerdDinners;集成安全性= TRUE;连接超时= 30;
        使用(VAR DB =新NerdDinners(的ConnectionString))
        {

            俱乐部club1 =新东家();
            俱乐部club2 =新东家();
            俱乐部club3 =新东家();


            VAR的查询=从o在db.Clubs
                        其中,(P => p.ClubName ==club1)
                        选择o;

            返回query.ToList();





        }
    }
 

解决方案

而不是在哪里(P => p.ClubName ==club1)使用方法:

  VAR的查询=从o在db.Clubs
            其中,o.ClubName ==club1
            选择o;
 

可能是你正在混淆方法链接它会是:

  VAR的查询= db.Clubs.Where(P => p.ClubName ==club1);
 
expresii 2019中文破解版 数字书法水墨软件下载 v2019.11.13 附带安装教程 安下载

I have entity framework code as shown below.I am getting following error in where condition.

Cannot convert lambda expression to type 'bool' because it is not a delegate type

How to overcome this error? What is the reason for this error?

    static void Main(string[] args)
    {

        ClubCreation();
        List<Club> selectedClubs = GetClubs("club1");

    }

    public static void ClubCreation()
    {

        string connectionstring = "Data Source=.;Initial Catalog=NerdDinners;Integrated Security=True;Connect Timeout=30";
        using (var db = new NerdDinners(connectionstring))
        {

            Club club1 = new Club();
            club1.ClubName = "club1";

            Club club2 = new Club();
            club2.ClubName = "club2";

            Club club3 = new Club();
            club3.ClubName = "club3";

            db.Clubs.Add(club1);
            db.Clubs.Add(club2);
            db.Clubs.Add(club3);

            int recordsAffected = db.SaveChanges();


        }
    }

    public static List<Club> GetClubs(string clubName)
    {
        string connectionstring = "Data Source=.;Initial Catalog=NerdDinners;Integrated Security=True;Connect Timeout=30";
        using (var db = new NerdDinners(connectionstring))
        {

            Club club1 = new Club();
            Club club2 = new Club();
            Club club3 = new Club();


            var query = from o in db.Clubs
                        where (p => p.ClubName == "club1")
                        select o;

            return query.ToList();





        }
    }

解决方案

Instead of where (p => p.ClubName == "club1") use:

var query = from o in db.Clubs
            where  o.ClubName == "club1"
            select o;

May be you are confused with method chaining where it would be:

var query = db.Clubs.Where(p => p.ClubName == "club1");

 
精彩推荐