lambda inner join and select all

12,397

If you want details of both tables, then you could have:

List<AllDetails> myObject = tableNames.Join(tableSchool, x => x.sID, s => s.schoolID, ((x, s) => new AllDetails(x, s))).ToList();

where:

public class AllDetails
    {
        private TableName tabName;
        private TableSchool tabSchool;

        public AllDetails(TableName tableName, TableSchool tableSchool)
        {
            //Assign fields here
        }
}
Share:
12,397
zey
Author by

zey

Updated on June 04, 2022

Comments

  • zey
    zey almost 2 years

    Here is how I inner join in lambda ,

    var myObject = tableNames.Join(tableSchool,  x => x.sID , s => s.schoolID ,  
    ( (x,s) => new {   }  ) ).ToList();
    

    I have many fields in both tableNames and tableSchool .
    By my lambda query , if I have 10 fields in tableNames , I've to write down all of 10 fields in new { } 10 times.
    What I want to know is how can I select all fields of tableName table and one field from tableSchool .

    Example

    tableName     tableSchool
    ---------     ------------ 
    Nfield1       Sfield1
    Nfield2       Sfield2
    Nfield3       Sfield3
    Nfield4
    Nfield5
    

    I want to get all fields from tableName and just one field (Sfield1) from tableShcool . I want to bind this datasource to asp:GridView :)

  • zey
    zey almost 11 years
    I want to bind this to asp.net GridView datasource .