0

I am trying to find an object in my database that meets two conditions, I did a search on stackoverflow and found this one which looks exactly like what I need. However, I have this code:

if (db.MinimumProductInfo.Find(pc => pc.ItemCode == productInfoWithNote.ItemCode && pc.Region == productInfoWithNote.Region))

and I am receiving this error:

Cannot Convert Lambda Expression to type 'object[]' because it is not a delegate type.

MinimumProductInfo is my class and productInfoWithNote is the viewmodel that I pass in to the method.

djblois
  • 963
  • 1
  • 17
  • 52

1 Answers1

1

Try using FirstOrDefault which will return null if no object meets the conditions:

 var myObject = db.MinimumProductInfo.FirstOrDefault(pc => pc.ItemCode == 
        productInfoWithNote.ItemCode && pc.Region == productInfoWithNote.Region);

    if(myObject != null)
    {
         // use your object here
    } 

NOTE: Find method returns the first match element if exists and if not it will return the default value of element's type and you are using it like it will return a boolean value.

Abdullah Dibas
  • 1,499
  • 1
  • 9
  • 13