【发布时间】:2021-11-10 14:31:05
【问题描述】:
我有以下 LINQ 查询,我想将其作为具有相关连接等的模型返回。
var query = (from wi in context.WorkItems
join mi in context.MaintenanceItems
on new { Id = wi.MaintenanceItemID }
equals new { Id = mi.MaintenanceItemID }
join p in context.Properties
on new { Id = mi.PropertyID }
equals new { Id = p.PropertyID }
join l in context.Locations
on new { Id = p.LocationID }
equals new { Id = l.LocationID }
join c in context.Categories
on new { Id = mi.CategoryID }
equals new { Id = c.CategoryID }
join sc in context.SubCategories
on new { Id = mi.SubCategoryID }
equals new { Id = sc.SubCategoryID }
join pl in context.PickLists
on new { Id = wi.PriorityFlag, V = "Priority" }
equals new { Id = pl.ValueKey, V = pl.ValueType }
where wi.AssignedTo1 == username
orderby wi.PriorityFlag descending, wi.PriorityIndex, wi.WorkItemID
select new {
wi.WorkItemID,
wi.PriorityFlag,
wi.PriorityIndex,
wi.CompletionDateTime,
l.LocationName,
p.PropertyFullName ,
wi.AssignedTo1,
wi.AssignedTo2,
wi.AssignedTo3,
c.CategoryName,
sc.SubCategoryName,
PriorityDesc = pl.ValueTitle
});
我的模型包含一个 WorkItem 实体,查询可以返回多个实体,然后相关实体填写所有外键的描述性值等。
显然使用查询我创建了一个匿名类型,但我不确定如何将其转回我需要的完全充实的已知类型?
【问题讨论】:
标签: c# asp.net entity-framework