21
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;} 
    }

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

i have list of CourseDetail,RefUIDByCourse and RefData now for the courseser exist in coursedetail i have to create list of CourseSummary.

one thing i can do is do for loop for coursedetail and fetch respective refdata using linq query and create a object of coursesummary and add it in list.

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

Radhi
  • 6,289
  • 15
  • 47
  • 68
  • 5
    Please post the code you have written so far. People generally do not like to just write your code for you. As it is, this is a work description, not a question. – Mitch Wheat Feb 18 '11 at 06:25
  • sorry mitch because of company policy i can not provide the code... but i would try to replicate same with some different example and post it. – Radhi Feb 18 '11 at 06:48
  • @Radhi:ohhh...please summarize your problem in some dummy code and then paste it. – santosh singh Feb 18 '11 at 06:53
  • updated the post with sample code... – Radhi Feb 18 '11 at 06:56
  • @Radhi - It would be easier to read if you removed the extra line breaks. – Greg Feb 18 '11 at 06:58
  • 2
    You need to make some sort of effort to write this yourself, and then ask for help when needed. You can't expect other people to put your program together from scratch. – Adam Rackis Feb 18 '11 at 07:27
  • @Radhi:I agree with **Adam**.Please make some effort to write the query and then asked question.It's take a lot of time to prepare data for these 4 classes. – santosh singh Feb 18 '11 at 09:30

1 Answers1

42

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 
    });

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 };
Erik Philips
  • 53,428
  • 11
  • 128
  • 150
Adam Rackis
  • 82,527
  • 56
  • 270
  • 393
  • and i want final result as collection of people which contains list of peopletype associated with it.... so i think my situation is different then the query you wrote... or else let me know if i am missing anything – Radhi Feb 18 '11 at 06:46
  • Why do you say that? I would think Person has a PersonType property, which matches up with one and only one PersonType.TypeID. If this were a database schema PersonType.TypeID would be the PK. Am I missing something? – Adam Rackis Feb 18 '11 at 06:47
  • @Radhi I'm afraid I don't follow. I was just trying to give you a very general join form for Lambdas. You're going to give a lot more detail in your question. Having said that, the short answer is you can apply whatever where you want to filter this down. – Adam Rackis Feb 18 '11 at 06:49