I have an extension method on an Enum called GetName
which returns a string. I'm using it in linq to entity framework to select rows with a specific product name. However, when the code is getting executed it's throwing a NotSupportedException
LINQ to Entities does not recognize the method System.String GetName(Tool.ViewModels.Product) method, and this method cannot be translated into a store expression.
Here is the code I am executing:
try
{
//Linq to Entity Framework
var contextRow = Contexts.Data.Source.SingleOrDefault(p => p.Product == Product.ProductOne.GetName());
}
catch (Exception e)
{
throw e;
}
Does Linq not recognize extension methods in its evaluations? Or is there something more going on?