LINQ to Entities 无法识别 select 部分中的方法
LINQ to Entities does not recognize the method inside the select section
我需要 AddYears(2)
在 select new ShowRequestsModel
。我怎样才能做到这一点?它抛出异常
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 = req.PurchasedDate.AddYears(2),
IsWarantyExpired = false
})
.Sort(sortField, sortBy);
你需要DbFunctions
class(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);
我需要 AddYears(2)
在 select new ShowRequestsModel
。我怎样才能做到这一点?它抛出异常
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 = req.PurchasedDate.AddYears(2),
IsWarantyExpired = false
})
.Sort(sortField, sortBy);
你需要DbFunctions
class(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);