maxlego
asked on
Dynamic LINQ
Hi!
I know there is way to build linq dynamicalli with Expression class and i was struggling for hours to make following code dynamic:
public IQueryable<T> OrderByGuid<T>(IQueryable< T> query, string fieldName) where T : Ii18n
{
switch (fieldName)
{
case "X":
return query.OrderBy(x => x.i18ns.SingleOrDefault(
y => y.LanguageID == CurrentLanguageID && y.ValueID == x.X).Value);
/**
.
.
.
etc.
**/
}
return null;
}
The idea is that i have lists that contain language-dependent columns and when i order by that column, I want it to be ordered by the value of current language.
Regards
Max
I know there is way to build linq dynamicalli with Expression class and i was struggling for hours to make following code dynamic:
public IQueryable<T> OrderByGuid<T>(IQueryable<
{
switch (fieldName)
{
case "X":
return query.OrderBy(x => x.i18ns.SingleOrDefault(
y => y.LanguageID == CurrentLanguageID && y.ValueID == x.X).Value);
/**
.
.
.
etc.
**/
}
return null;
}
The idea is that i have lists that contain language-dependent columns and when i order by that column, I want it to be ordered by the value of current language.
Regards
Max
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.