【发布时间】:2015-10-02 20:59:30
【问题描述】:
我有以下 Linq,我可以像这样使用 LINQ 来获取 IsPremiumUser 和 IsLawFirm 的值吗?或者有没有其他好的方法可以做到这一点?
我需要的是根据供应商 ID 获取 IsPremiumUser 和 IsLawFirm 的值。我不想添加任何 foreach 来完成这项工作,我可以使用 LINQ 来获取这些值吗
var supplierListQuery =
(from sup in db.PPSuppliers
select new SearchResultSupplierViewModel
{
SupplierId = sup.PPSupplierId,
SupplierLocation = sup.LocationsForDisplay,
CreatedDate = (DateTime)sup.CreatedDate,
PPMemberId = sup.PPMemberId,
IsPremiumUser =
(from u in db.PPSubscriptions
join s in db.PPSubscriptionPlans on u.SubscriptionPlanId equals s.SubscriptionPlanId
where u.PPMemberId == sup.PPMemberId && u.SubscriptionEndDate >= System.DateTime.Now
orderby u.SubscriptionStartDate descending
select s).FirstOrDefault().isPremium,
IsLawFirm =
(from l in db.PPSupplierSupplierTypes
join f in db.PPSupplierTypes on l.PPSupplierTypeId equals f.PPSupplierTypeId
where l.PPSupplierId == sup.PPSupplierId && f.PPSupplierTypeId == 1
select l).Any()
});
【问题讨论】:
标签: c# asp.net-mvc linq linq-to-sql