How can I call a method in a class and use that for my selection in LINQ? Well.. this is what I mean: My class "Law" keeps a list of Versions and offers a method to get the current version:
public class Law
{
...
public virtual IList<LawVersion> Versions {get; set;}
public LawVersion CurrentVersion()
{
// Given a list of Laws, how can I use this method in my selection clause?
return Versions.OrderByDescending(x => x.CreationDate).First();
}
}
I would like to obtain a List of all current LawVersions. I have tried like this:
Context.Laws.Select(x => x.CurrentVersion())
which ends in
"LINQ to Entities does not recognize the method.. cannot be translated into a store expression"