我使用Exp-Func创建了两个选择器我想在一个查询中执行它们。代码如下:
Expression<Func<Scholar, ScholarCultureWatchListView>> selector = z => new ScholarCultureWatchListView
{
ScholarId = z.ID,
Name = z.FirstName + " " + z.LastName
};
Expression<Func<Scholar, ScholarCultureWatchListView>> selector2 = z => new ScholarCultureWatchListView
{
Grade = z.CurrentGrade
};
var result= from s in db.Scholars
select new ScholarCultureWatchListView
{
**?????What is write here (selector, selector2)**
}
public class ScholarCultureWatchListView
{
public long ScholarId { get; set; }
public string Name { get; set; }
public Grade? Grade { get; set; }
public bool? HoldOverSkip { get; set; }
public Grade? GradeHoldOver { get; set; }
public bool? Iep { get; set; }
public int Tardies { get; set; }
public int Absences { get; set; }
public int YtdSuspensions { get; set; }
....
}
请解决我的问题。 感谢
答案 0 :(得分:0)
如果你想从一次调用中获得两个单独的ScholarCultureWatchListView
实例,你可以这样做(你根本不需要选择器):
var result = from s in db.Scholars
select new[]
{
new ScholarCultureWatchListView
{
ScholarId = s.ID,
Name = s.FirstName + " " + z.LastName
},
new ScholarCultureWatchListView
{
Grade = z.CurrentGrade
},
};