LINQ to Entities does not recognize my method

前端 未结 1 372
独厮守ぢ
独厮守ぢ 2020-12-19 19:21

I want to convert date and time to Persian in LINQ select but linq can not recognize my method :

LINQ to Entities does not recognize the method \'

相关标签:
1条回答
  • 2020-12-19 19:37

    EF cannot translate your custom method to SQL. You can inject a .AsEnumerable() call to change the underlying context from EF to Linq-to-Objects:

    var result = (from ord in db.vw_orders
                  where ord.uid == user.id
                  orderby ord.order_date descending select ord
                 )
                 .AsEnumerable()
                 .Select(o => new { o.id,
                                    date = Tools.toPersianDateTime((DateTime)o.order_date),
                                    o.is_final, 
                                    o.status, 
                                    o.image_count, 
                                    o.order_count, 
                                    o.total_price }
                        );
    
    0 讨论(0)
提交回复
热议问题