[英]Linq-to-sql error: 'int[]' does not contain a definition for 'Contains'
I am having an error:我有一个错误:
Error 2 'int[]' does not contain a definition for 'Contains' and the best extension method overload 'System.Linq.Enumerable.Contains(System.Collections.Generic.IEnumerable, TSource)' has some invalid arguments错误 2 'int[]' 不包含 'Contains' 的定义和最佳扩展方法重载 'System.Linq.Enumerable.Contains(System.Collections.Generic.IEnumerable, TSource)' 有一些无效的 arguments
This is my code:这是我的代码:
public partial class mymymy : System.Web.UI.Page
{
int[] validType = { 2, 3, 4, 5, 6, 8, 13, 14, 16, 22 };
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LinqDataSource_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
using (var dc = new soxMainDataContext())
{
var qry = from item in dc.LeaveRequests
where **validType**.Contains(item.Type)
&& item.MgtApproval == null
select item;
e.Result = qry;
}
}
}
I strongly suspect that item.Type
isn't an int
. 我强烈怀疑
item.Type
不是int
。 Is it an enum? 这是枚举吗? If so, try explicitly casting:
如果是这样,请尝试显式转换:
var qry = from item in dc.LeaveRequests
where validType.Contains((int) item.Type)
&& item.MgtApproval == null
select item;
Alternatively, as dot notation: 或者,作为点符号:
var query = dc.LeaveRequests.Where(item => validType.Contains((int) item.Type)
&& item.MgtApproval == null);
item.Type
不是int
。
var consulta = from pr in lsprodcts
where pr.nProductoID.ToString().Contains(Idproducto.ToString())
select new
{
pr.nProductoID,
ProdName = pr.cNombre,
pr.cDescripcion,
};
` `
Don't forget to import Linq with using System.Linq;
不要忘记
using System.Linq;
at the very top of the class.在 class 的最顶端。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.