我有错误:
错误2’int []’不包含’Contains’的定义,最好的扩展方法重载’System.Linq.Enumerable.Contains(System.Collections.Generic.IEnumerable,TSource)’有一些无效的参数
这是我的代码:
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; } } }
解决方法
我强烈怀疑item.Type不是int.是枚举吗?如果是这样,请尝试显式转换:
var qry = from item in dc.LeaveRequests where validType.Contains((int) item.Type) && item.MgtApproval == null select item;
或者,作为点符号:
var query = dc.LeaveRequests.Where(item => validType.Contains((int) item.Type) && item.MgtApproval == null);