LINQ to Entities无法识别选择部分中的方法

时间:2018-10-11 13:45:42

标签: entity-framework linq linq-to-sql linq-to-entities

我需要在[ { "kode": "8784", "nama": "drg.MELANI SARI TANJUNG" }, { "kode": "8848", "nama": "drg.ARIEF KURNIAWAN" }, { "kode": "8873", "nama": "drg.SRI ARIANI SUGIARTI" } ]AddYears(2)。我怎样才能做到这一点?引发异常

select new ShowRequestsModel

1 个答案:

答案 0 :(得分:3)

您需要DbFunctions类(System.Data.Entity),尤其是它的 AddYears()方法

var requests = (from req in db.PartRequests
            join info in db.UsersInfos on req.UserId equals info.aspnet_UserId
            join prodName in db.Products on req.ProductId equals prodName.Id
            join partRequestStatus in db.PartRequestStatus on req.PartRequestStatusId equals partRequestStatus.Id           
            select new ShowRequestsModel
            {                                                                                                                
                WarantyExpirationDate = DbFunctions.AddYears(req.PurchasedDate, 2),
                IsWarantyExpired = false
            })
            .Sort(sortField, sortBy);