Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq-to-sql error: 'int[]' does not contain a definition for 'Contains'

Tags:

c#

linq-to-sql

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

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;
        }
    }
}
like image 790
Yves Avatar asked Jul 01 '09 13:07

Yves


3 Answers

I strongly suspect that item.Type isn't an 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);
like image 73
Jon Skeet Avatar answered Nov 13 '22 08:11

Jon Skeet


item.Type isn't an int.

like image 25
mqp Avatar answered Nov 13 '22 08:11

mqp


var consulta = from pr in lsprodcts 
               where pr.nProductoID.ToString().Contains(Idproducto.ToString())
               select new
               {
                   pr.nProductoID,
                   ProdName = pr.cNombre,
                   pr.cDescripcion,
               };

`

like image 35
navi_osoro Avatar answered Nov 13 '22 07:11

navi_osoro