EF 4: The specified type member '*' is not supported in LINQ to Entities

前端 未结 2 592
被撕碎了的回忆
被撕碎了的回忆 2021-01-21 08:58

i have a mapped-class like this:

[Table(\"MyTable\")]
class MyClass         
{   
        //properties; id, name, etc...

        private string _queuedToWHTime          


        
相关标签:
2条回答
  • 2021-01-21 09:39

    You cannot query with EF on custom properties. The custom property cannot be translated in SQL.

    You can do this to force the orderby to be done 'in-memory'.

    var searchRslt = queryableNews
        .AsEnumerable()
        .OrderBy(m => m.QueuedToWHTime_DateTime)
        .ToList();
    
    0 讨论(0)
  • 2021-01-21 09:53

    The issue is here:

    var searchRslt=(from m in queryableNews
    orderby m.QueuedToWHTime_DateTime descending
    select m).ToList();
    

    you are trying to use the property .QueuedToWHTime_DateTime, but that does not exist in the database. You need to use the names that are used in the database. In this case .QueuedToWHTime So:

    var searchRslt=(from m in queryableNews
    orderby m.QueuedToWHTime descending
    select m).ToList();
    

    If the database propery is not usable in this scenario, you will have to pull the entire list, convert it to an IEnumerable (any will do), then filter/order that IEnumerable by its property.

    Something like this:

    var result = queryableNews.ToList().OrderbyDescending(x=>x.QueuedToWHTime_DateTime).ToList();
    
    0 讨论(0)
提交回复
热议问题