Using “where”: Cannot convert lambda expression to type 'bool'

前端 未结 5 1156
感动是毒
感动是毒 2021-01-07 00:35

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

Cannot convert lambda expression to type \'bool\' because

相关标签:
5条回答
  • 2021-01-07 01:11

    In asp mvc Razor while i tried:

    @if (modelItem => item.Id == 1)
     {
    
    <span class="badge progressbar-success">Approved</span> 
    
     }
    

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

    Solution:

    @if (Model.FirstOrDefault().Id == 1)
    {
    
    <span class="badge progress-bar-success">Approved</span>
    
    }
    

    Hope helps someone.

    0 讨论(0)
  • 2021-01-07 01:21

    The => syntax is used in the method chain notation. You probably also want to use the clubName variable instead of "club1".

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

    which does the same as this (which is the correct syntax for your query):

    var query = from o in db.Clubs
                where o.ClubName == clubName
                select o;
    
    0 讨论(0)
  • 2021-01-07 01:36

    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");
    
    0 讨论(0)
  • 2021-01-07 01:37
            var query = from o in db.Clubs
                        where o.ClubName == "club1"
                        select o;
    
    0 讨论(0)
  • 2021-01-07 01:37
    var query = from o in db.Clubs
                where o.ClubName == "club1"
                select o;
    
    0 讨论(0)
提交回复
热议问题