none
When EF does the join to fetch data from two tables RRS feed

  • Question

  • tell me when EF does the join to fetch data from two tables ?

    i know when we include keyword

    using (var context = new SchoolDBEntities())
    {
        var stud1 = (from s in context.Students.Include("Standard")
                    where s.StudentName == "Student1"
                    select s).FirstOrDefault<Student>();
    }

    beside include keyword when EF use join to fetch data from two tables. thanks

    Monday, October 9, 2017 12:26 PM

Answers

  • Hi Sudip_inn,

    To join you can use LINQ query as below:

     class Person
            {
                public string FirstName { get; set; }
                public string LastName { get; set; }
            }
    
            class Pet
            {
                public string Name { get; set; }
                public Person Owner { get; set; }
            }
    
     

     Simple inner join.

        var query = from person in people
                            join pet in pets on person equals pet.Owner
                            select new { 
                               OwnerName = person.FirstName, 
                               PetName = pet.Name };
         }
    

    Best Regards,

    Bob


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Sudip_inn Wednesday, November 1, 2017 8:39 AM
    Tuesday, October 10, 2017 12:56 PM