Linq实体硬编码列表

时间:2014-03-06 12:48:34

标签: c# linq entity-framework

这是我的视图模型

 public class ProcurementDisplayData
{
    public string Key { get; set;}
    public string Value { get; set;}  
}

如何对此列表进行硬编码。基本上,查询中的语法是什么

 var query = (from u in context.Jobs
                         join q in context.Quotations on u.QuotationId equals q.QuotationId
                         join v in context.Vessels on q.VesselId equals v.VesselId
                         join c in context.Customers on q.CustomerId equals c.CustomerId
                         where u.JobNo == JobNo
                         select new List<ProcurementDisplayData>
                         {
                            new { Key = "a" ,Value=u.JobNo},
                              new { Key = "b" ,Value=u.Vessel}


                         }).ToList();
            return query;

1 个答案:

答案 0 :(得分:2)

从数据库中获取JobNoVessel。然后在内存中创建列表:

var query = from u in context.Jobs
            join q in context.Quotations on u.QuotationId equals q.QuotationId
            join c in context.Customers on q.CustomerId equals c.CustomerId
            where u.JobNo == JobNo
            select new { u.JobNo, u.Vessel };

return query.AsEnumerable() // moves further processing to memory
            .Select(x => new List<ProcurementDisplayData> {
                              new { Key = "a", Value = x.JobNo },
                              new { Key = "b", Value = x.Vessel }
                           }).ToList();