Is it possible to define a column in one of my Linq to SQL entities such that it's calculated as part of the SQL query?
Here is my Entity class so far:
[Table(Name = "Products")]
public class ProductEntity
{
[Column(Name = "ModelNumber", IsPrimaryKey = true)]
public string ModelNumber { get; set; }
[Column(Name = "SerialNumber", IsPrimaryKey = true)]
public string SerialNumber { get; set; }
}
I want to add a new property like:
[Column]
public bool ActiveListing { get; set; }
Except its value should be calculated based on a complicated Linq query which I am executing elsewhere right now (not in SQL!):
context.GetTable<SalesRecords>().
Where(ah => ah.Date <= GlobalCoordinatedDateTime.Local).
Where(ah => ah.ProductModelNumber == ModelNumber && ah.ProductSerialNumber == SerialNumber).
OrderByDescending(ah => ah.Date).
FirstOrDefault().Status == Statuses.Active;
My best guess is that I could use AssociationAttribute
but I don't know how to do that when there could be more than one match in the "SalesRecords" table and I want to get the first after applying some ordering.
EDIT: My question is not the same as a simple "computed column" as seen in this question, I need to compute the value using data stored in different tables, outside of the entity its self.