本文介绍了Lambda表达式的捧场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class CourseDetail
    {
        public CourseDetail();
        public string CourseId { get; set; }
        public string CourseDescription { get; set; }
        public long CourseSer { get; set; }
    }

 public class RefUIDByCourse
    {
        public long CourseSer {  get;  set; }
        public double DeliveredDose{ get; set; }
        public double PlannedDose{ get; set; }
        public string RefUID {  get;  set; }
     }
 public class RefData
    {
       public double DailyDoseLimit {  get;  set; }
       public string RefName {  get;  set; }
       public string RefUID {  get;  set; }
       public double SessionDoseLimit {  get;  set; }
    }

public class CourseSummary
    {
          public long CourseSer { get; set; }
          public double DeliveredDose{ get; set; }
          public double PlannedDose{ get; set; }
          Public List<RefData> lstRefData {get;set;}
    }



其一courseSer有可以在多个RefUID RefUIDByCourse
和每RefUID会有RefData一个记录

For one courseSer there can be multiple RefUID in RefUIDByCourseand for every RefUID there will be one record in RefData

我有CourseDetail,RefUIDByCourse和RefData
名单现在对于courseser在coursedetail存在我要创建CourseSummary列表。

有一件事情我可以做的是循环做coursedetail并使用取各自refdata LINQ查询并创建coursesummary的对象,并在列表中添加它。

,但有什么办法一个LINQ做查询,而不是通过

but is there any way to do it by one linq query instead of doing loop through

推荐答案

对于加入的拉姆达做循环是参与了一点 - 这里的一个简单的例子:

The lambda for a Join is a bit involved - here's a simple example:

List<Person> People = new List<Person>();
List<PersonType> PeopleTypes = new List<PersonType>();

var joined = People.Join(PeopleTypes, PeopleKey => PeopleKey.PersonType, PeopleTypesKey => PeopleTypesKey.TypeID, (Person, PersoneType) => new { Name = Person.Name, TypeID = PersoneType.TypeID });



我通常会发现查询语法很多比lambda表达式加盟

I usually find the query syntax a lot more readable than lambdas for joining

        var joined2 = from p in People
                      join pType in PeopleTypes
                      on p.PersonType equals pType.TypeID
                      where p.Name.StartsWith("whatever")
                      select new { Name = p.Name, TypeID = pType.TypeID };

这篇关于Lambda表达式的捧场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 05:55