So I have this multilingual datamodel: Product -> ProductTranslation
Product
has anId
property.ProductTranslation
has aCulture
(e.g. 'nl') and aName
property.
I already have a working query that flattens a product for a specific language to a ProductModel (using Automapper).
ProductModel
has anId
and aName
property.
ProductModel.Name
contains the Name
from the appropriate ProductTranslation
, which I determine in the query by comparing the client application culture to ProductTranslation.Culture
.
So far all good and no LINQKit involved.
Now I'd like to sort the products returned by ProductTranslation.Name
. My question is if this can be using LINQKit. I do want to do the sorting on the database side, so materializing and doing it on the client side is no option (left out paging to simplify the example here).
I do have an expression already that will determine the correct translation:
Expression<Func<ICollection<ProductTranslation>, ProductTranslation>> expression =
translations => translations.FirstOrDefault(t => t.Culture.Equals(cultureName))
?? translations.FirstOrDefault();
Can I somehow expand on this to get the Name
property from the ProductTranslation
this returns and apply it as a sorting expression?
Thanks in advance, cheers!