convert IQueryable to

前端 未结 6 789
滥情空心
滥情空心 2020-12-16 18:01

I want to select my price level in database to compare with the an integer number. But It is error : Operator \'==\' cannot be applied to operands of type \'System.Linq.IQue

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-16 18:41

    when you have the result from LinQ expression you will always have the list of result set.

    So in your code when you are querying as below :

    var list_pricelevel = from c in cm.DataContext.Customers where c.WebAccount == userName select c.PriceLevel;

    The list_pricelevel will be in the form of List ie IQueryable list,

    so you have to get only one element to check with one element

    so use the below code :

    if (list_pricelevel.Single() == 3) 
    { 
      Response.Write("Welcome");  
    }
    
    or
    
    if (list_pricelevel.First() == 3) 
    { 
      Response.Write("Welcome");  
    }
    
    
    both the above code gives you only one result set value so you can equate with 3 for validation.
    

提交回复
热议问题