查询值IQueryable如何转换为为一个实体类型?
private void Window_Loaded(object sender, RoutedEventArgs e)
{
applies001 = hkhy001Context.DOApplies;//objectset集合赋值
projects001 = hkhy001Context.PUProjects;
var info1 = from a in applies001
join p in projects001 on a.ProjectID equals p.ProjectID
select new lmodel { FileCode = a.FileCode, Applicant = a.Applicant,
ApplyDate = a.ApplyDate, ProjectName = p.ProjectName,
Owner = p.Owner, ProjectAttach = p.ProjectAttach };
lmodel ttt = null;
ttt =info1;
listviewDoc.DataContext = ttt;//绑定
}
无法将类型“System.Linq.IQueryable<HKHY.Module.DocumentManagement.lmodel>”隐式转换为“HKHY.Module.DocumentManagement.lmodel”。存在一个显式转换(是否缺少强制转换?)
------最佳解决方案--------------------select new
{
FileCode = a.FileCode,
Applicant = a.Applicant,
ApplyDate = a.ApplyDate,
ProjectName = p.ProjectName,
Owner = p.Owner,
ProjectAttach = p.ProjectAttach
};
------其他解决方案--------------------不过楼主肯定又希望结果集不是匿名类,好方便他往逻辑层传值。
俺很悲摧地告诉你,这个地方是没法绕过去的,只有两种方法处理,第一,写一个强转为lmodal的方法,这个太别扭了;第二,另外定义一个lmodalSummary的类,专门用于数据输出,实际上,这种类是广泛采用的,本身表结构直接应用于呈现就不科学。
------其他解决方案--------------------var info1 = from a in applies001
join p in projects001 on a.ProjectID equals p.ProjectID
select new lmodel { FileCode = a.FileCode, Applicant = a.Applicant,
ApplyDate = a.ApplyDate, ProjectName = p.ProjectName,
Owner = p.Owner, ProjectAttach = p.ProjectAttach };