Click here to Skip to main content
15,908,618 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi.. I am using 2 Tables say Person and Country.

Person
Name--Occupation--Countryid
Mark--Sales Man --1003
William--Developer--1001

Country
id--Name
1001--San Fransisco
1002--Las Vegas
1003--New York

Here the Person references Country (country id). Consider the classes are already auto generated through EntityFramework and I have Persons and Countries as class name to the respected tables.

Now I am getting the Persons Data thorough the following
C#
this.ObjectContext.Persons.Where(x=>x.Countryid==1003).ToList<Persons>();


This actually returns PersonsList but PersonsList[0].Country (For example: I am getting the first element of the list here) would be null at this case.

So here I am using Includes with the above code
C#
this.ObjectContext.Persons.Includes("Country").Where(x=>x.Countryid==1003).ToList<Persons>();


Now PersonsList[0].Country will have the data for the Country class which that person row references too.

My question is.. Are there any options where I could get this Country data with out this Includes class. ?

Because under my case if I am using this Include class it tooks 2-3 mins (because of the huge data) to process the query. This is mainly because the query generated by EntityFramework is having one more LeftOuterJoin of Country with Persons.

If I am not using the Include then it take only few seconds to process the query. Because here the LeftOuterJoin is skipped. So is there is anyway so that I can access the data of the Country class with out Include.. ??


I have tried my level best to explain this. If you couldn't get this plz feel free to ask me your doubt..

Thanks..
Posted

1 solution

If you want to join both the table and to get the data as listing type

var listNew=(from a in Countries
             join b in Persons on a.CountryId equals b.CountryId
             select new {
             CountryName=a.Name,
             PersonName=b.PersonName
              }).Tolist();

Something like this
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900