比较2个整数时无法转换lambda表达式

时间:2012-07-06 16:33:18

标签: c# linq-to-entities

无法将lambda表达式转换为类型'bool',因为它不是委托类型

比较if语句中的2个整数“if(UserLevelID => dbMinimunlevelID)”

如何将包含计数的变量与另一个整数进行比较?

 //Check if user has enough credits to create ClassCharacter       
        public bool CheckMinimunCreditforClassCharacter(Guid UserID, int ClassCharacterID, int Levelid)
        {

        bool Results = true;

        //Check Character Creation Rules
        int dbMinimunlevelID = 0;
        bool AdditionalCharactersRequired = false;
        int AdditionalCharactersPoints = 0;

        var query = (from o in db.ClassCharacters
                     where o.ClassCharacterID == ClassCharacterID
                     select o);   

        foreach (var v in query)
        {
            dbMinimunlevelID = v.MinimumPoints;
            AdditionalCharactersRequired = v.AdditionalCharactersRequired;
            AdditionalCharactersPoints = v.AdditionalCharactersPoints;
        }

        if (dbMinimunlevelID > 0)
        {
            //Check User existing Characters
            int UserLevelID = db.Characters.Where(o => o.UserId == UserID)
                         .Max(o => o.LevelID);

            //************ Here is where the error appears
            if (UserLevelID => dbMinimunlevelID)
            {
                Results = true;
            }
            else
            {
                Results = false;
            }

        }

        return Results;
    }

2 个答案:

答案 0 :(得分:10)

替换:

if (UserLevelID => dbMinimunlevelID)

使用:

if (UserLevelID >= dbMinimunlevelID)

=>是lambda运算符,而>=(大于或等于)用于比较

答案 1 :(得分:4)

您正在使用=>创建一个lambda表达式...它是一个正确的箭头。

使用>=进行比较。