0

我使用 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; }
    ....
}

请解决我的问题。谢谢

4

1 回答 1

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
                 },
             };
于 2013-10-10T11:44:36.370 回答