C# Linq-to-sql 错误:“int[]”不包含“Contains”的定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1069106/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linq-to-sql error: 'int[]' does not contain a definition for 'Contains'
提问by Yves
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)' 有一些无效的参数
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;
}
}
}
采纳答案by Jon Skeet
I strongly suspect that item.Type
isn't an int
. Is it an enum? If so, try explicitly casting:
我强烈怀疑这item.Type
不是int
. 是枚举吗?如果是这样,请尝试显式转换:
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);
回答by mqp
item.Type
isn't an int
.
item.Type
不是int
.
回答by navi_osoro
var consulta = from pr in lsprodcts
where pr.nProductoID.ToString().Contains(Idproducto.ToString())
select new
{
pr.nProductoID,
ProdName = pr.cNombre,
pr.cDescripcion,
};
`
`