我想在数据库中选择我的价格水平与整数进行比较。但它是错误的:运算符“==”不能应用于“System.Linq.IQueryable”和“int”类型的操作数。 这是我的代码:
if (Request.IsAuthenticated){
CustomerModels cm = new CustomerModels();
string userName = Page.User.Identity.Name;
var list_pricelevel = from c in cm.DataContext.Customers
where c.WebAccount == userName
select c.PriceLevel;
if (list_pricelevel == 3) {
Response.Write("Welcome");
}
}
最佳答案
var list_pricelevel
根据定义,这不是 int
,因为可以返回不止一行。
我不使用 SQL 语法(仅使用 lambda),但最后您需要等效于 .FirstOrDefault
或 Single
或 First
。基本占第一排。
关于c# - 将 IQueryable<int> 转换为 <int>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8293263/