Unfortunately, you cannot use the Equals implementation in a query for EF because it cannot decompile your code to see how this is done. You should use the Any method with the predicate expression:
bool exists = storeDB.ShippingInformations .Any(info => info.CustomerID == other.CustomerID && info.CountryID == other.CountryID );
(I made the fields just to show the idea, other is the ShippingInformation you are looking for.)
If there are many places where you want to reuse this expression, you can use LinqKit to combine the expressions:
private static Expression<Func<ShippingInformation, ShippingInformation, bool>> isEqualExpr = (info, other) => info.CustomerID == other.CustomerID && info.CountryID == other.CountryID;
Such code should be placed in the data layer.
I am not 100% sure if the above code works. It is possible that EF will not allow the use of a βdifferentβ object in the query expression. If this is the case (tell me), you will need to modify the expression to accept all the values ββof the primitive type for comparison (in our example, this would be Expression<Func<ShippingInformation, int, int, bool>> ).
source share