Entity Framework
  • Sortare folosind expresii definite intr-un dictionar - obtin eroarea "LINQ to Entities only supports casting EDM primitive or enumeration types" cand incerc sa sortez dupa orice altceva decat string
    • Ca sa rezolv trebuie sa includ campurile definite in expresii in obiecte anonime, ca in exemplul de mai jos.
var mappings = new Dictionary<string, Expression<Func<UrlAttribute, object>>>
{
    { "Url", x => new { x.Url } },
    { "Type", x => new { x.TypeValue } },
    { "ValidFrom", x => new { x.ValidFrom } }, 
};
...
list.OrderBy(mappings[sortField]).Skip(startRowIndex).Take(maximumRows).ToList();
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License