【发布时间】:2016-08-17 08:15:52
【问题描述】:
我有这个 linq 调用:
PropertyViewModel propertyModel = null;
propertyModel = (from property in db.LoanProperties
join tenant in db.Tenants
on property.PropertyId equals tenant.PropertyId
where property.LoanApplicationId == newApplication.LoanId
select new PropertyViewModel(
propertyModel.AddressLine1 = property.AddressLine1,
propertyModel.AddressLine2 = property.AddressLine2,
propertyModel.TotalRentPerAnnum = property.TotalRentPerAnnum,
propertyModel.Tenants = db.Tenants.Where(s => s.PropertyId == property.PropertyId).ToList()
));
我的视图模型:
public class PropertyViewModel
{
public string AddressLine1 { get; set; }
public string AddressLine2 { get; set; }
public decimal? TotalRentPerAnnum { get; set; }
public List<TenantViewModel> Tenants { get; set; }
}
我想从我的 TenantViewModel 中的 linq 查询中转换属性下的租户。
我怎样才能做到这一点?
我指的是propertyModel.Tenants的最后一行。
【问题讨论】:
-
然后在其末尾添加一个 .select 并进行投射
-
那么实际的问题是什么?
-
db.Tenants.Where(...).Select(t => new TenantViewModel { ... } -
为什么你要加入物业和租户,然后再分别查询
db.Tennatsdb.Tenants.Where(s => s.PropertyId == property.PropertyId).ToList()? -
@AdliMammadov 第一次加入可以去
标签: c# linq linq-to-sql linq-to-entities linq-to-objects