1

Error CS1929 'int[]' does not contain a definition for 'Contains' and the best extension method overload 'Queryable.Contains<int?>(IQueryable<int?>, int?)' requires a receiver of type 'IQueryable<int?

once i try to run the code this error comes out , i dont know how to fix it. this is the code

public void SendModelPallet(string IDs, StorageContext db)
{
    int[] ids = ViewModelsUtils.processIDs(IDs);
    PalletBoxes = db.ExternStoragePlaces.Where(c => ids.Contains(c.PalletPlaceID)).ToList();
    this.db = db;
}

Thanks in advance

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
B.Y
  • 39
  • 2
  • 9
  • 1
    `ids.Any(item => item = c.PalletPlaceID)` – Dmitry Bychenko Jul 17 '18 at 12:57
  • Does `ids.Contains(c.PalletPlaceID ?? int.MinValue)` compile? – mjwills Jul 17 '18 at 13:00
  • Is `c.PalletPlaceID` an `int` or an `int?` or something else ? if `int?`, see mjwills' comment. – Pac0 Jul 17 '18 at 13:09
  • Possible duplicate of [Check if list contains item from other list in EntityFramework](https://stackoverflow.com/questions/21641016/check-if-list-contains-item-from-other-list-in-entityframework) – mortb Jul 17 '18 at 13:15
  • int? but it doesn't compile , @mjwills – B.Y Jul 17 '18 at 13:21
  • int? but it doesn't compile @Pac0 – B.Y Jul 17 '18 at 13:21
  • 1
    Maybe Linq to SQL from EF has problems with null coalescing operator. Can you try using int?[] for your array instead ? – Pac0 Jul 17 '18 at 13:22
  • Does `ids.Contains((int)(c.PalletPlaceID ?? int.MinValue))` compile? – Magnetron Jul 17 '18 at 13:43
  • My suggestion should have compiled. What was the compiler error? – mjwills Jul 17 '18 at 21:57
  • @mjwills once i try your solution i get this error . Error CS0029 Cannot implicitly convert type 'System.Collections.Generic.List'to 'System.Collections.Generic.List' – B.Y Jul 24 '18 at 13:40
  • @Magnetron it doesnt compile cause of this error – B.Y Jul 24 '18 at 13:43
  • Error CS1061 'bool' does not contain a definition for 'ToList' and no extension method 'ToList' accepting a first argument of type 'bool' could be found (are you missing a using directive or an assembly reference?) @Magnetron – B.Y Jul 24 '18 at 13:43

2 Answers2

3

Just a guess here, but I remember having had problems with nulll coalescing in some Linq to SQL queries. I recommend you to try to declare your ids array as this :

int?[] ids = ViewModelsUtils.processIDs(IDs);

(use int?[]instead of int[] so this will match the type of your field)

Not sure about this, first because it doesn't seem to match the compilation error message, and secondly because I don't have a way to test this for the moment.

Pac0
  • 21,465
  • 8
  • 65
  • 74
3

Had the same issue while using Delegates[] and used to get the CS1929: 'Delegate?[]' does not contain a definition for 'Contains'

Just included the System.Linq namespace and works fine now.

Abhijit S
  • 319
  • 2
  • 12