Answers for "linq join"

SQL
3

linq join

var id = 1;
var query =
   from post in database.Posts
   join meta in database.Post_Metas on post.ID equals meta.Post_ID
   where post.ID == id
   select new { Post = post, Meta = meta };
Posted by: Guest on April-08-2020
0

how to write join query in linq c#

var locationInfo = entities.TagTemperatures    // your starting point - table in the "from" statement
            .Join(entities.ReverseGeoFenceAddresses, // the source table of the inner join
               tt => tt.TagTemperatureId,        // Select the primary key (the first part of the "on" clause in an sql "join" statement)
               rg => rg.TagTemperatureId,   // Select the foreign key (the second part of the "on" clause)
               (tt, rg) => new { TT = tt, RG = rg }) // selection
            .Where(TTandRG => TTandRG.TT.TagId == tag.TagId && TTandRG.TT.SampleTime > StartDate && TTandRG.TT.SampleTime < EndDate)
            .Select(X => new { X.TT.Latitude, X.TT.Longitude, X.TT.SampleTime, X.TT.TemperatureCelsius, X.TT.isAlert, X.TT.isYAlert, X.RG.FullAddress }).ToList();    // where statement
Posted by: Guest on July-22-2021
0

linq join

IList<Student> studentList = new List<Student>() { 
    new Student() { StudentID = 1, StudentName = "John", StandardID =1 },
    new Student() { StudentID = 2, StudentName = "Moin", StandardID =1 },
    new Student() { StudentID = 3, StudentName = "Bill", StandardID =2 },
    new Student() { StudentID = 4, StudentName = "Ram" , StandardID =2 },
    new Student() { StudentID = 5, StudentName = "Ron"  } 
};

IList<Standard> standardList = new List<Standard>() { 
    new Standard(){ StandardID = 1, StandardName="Standard 1"},
    new Standard(){ StandardID = 2, StandardName="Standard 2"},
    new Standard(){ StandardID = 3, StandardName="Standard 3"}
};

var innerJoin = studentList.Join(// outer sequence 
                      standardList,  // inner sequence 
                      student => student.StandardID,    // outerKeySelector
                      standard => standard.StandardID,  // innerKeySelector
                      (student, standard) => new  // result selector
                                    {
                                        StudentName = student.StudentName,
                                        StandardName = standard.StandardName
                                    });
Posted by: Guest on August-09-2021
1

join in linq c#

IList<string> strList1 = new List<string>() { 
    "One", 
    "Two", 
    "Three", 
    "Four"
};

IList<string> strList2 = new List<string>() { 
    "One", 
    "Two", 
    "Five", 
    "Six"
};

var innerJoin = strList1.Join(strList2,
                      str1 => str1, 
                      str2 => str2, 
                      (str1, str2) => str1);
Posted by: Guest on February-02-2021
0

linq join

IList<Student> studentList = new List<Student>() { 
    new Student() { StudentID = 1, StudentName = "John", Age = 13, StandardID =1 },
    new Student() { StudentID = 2, StudentName = "Moin",  Age = 21, StandardID =1 },
    new Student() { StudentID = 3, StudentName = "Bill",  Age = 18, StandardID =2 },
    new Student() { StudentID = 4, StudentName = "Ram" , Age = 20, StandardID =2 },
    new Student() { StudentID = 5, StudentName = "Ron" , Age = 15 } 
};

IList<Standard> standardList = new List<Standard>() { 
    new Standard(){ StandardID = 1, StandardName="Standard 1"},
    new Standard(){ StandardID = 2, StandardName="Standard 2"},
    new Standard(){ StandardID = 3, StandardName="Standard 3"}
};

var innerJoin = from s in studentList // outer sequence
                      join st in standardList //inner sequence 
                      on s.StandardID equals st.StandardID // key selector 
                      select new { // result selector 
                                    StudentName = s.StudentName, 
                                    StandardName = st.StandardName 
                                };
Posted by: Guest on August-09-2021

Code answers related to "SQL"

Browse Popular Code Answers by Language