public class CitiesList
{
public int cityId{ get; set; }
public int CountryId{ get; set; }
public string CITY { get; set; }
public List<CitiesList> GetCity()
{
//get city list
.
.
.
var query = from o in dsResult.Tables[0].AsEnumerable()
select new CitiesList
{
CITYID = o.Field<int>("CITYID"),
CITY = o.Field<string>("CITY")
};
List<CitiesList> lstDisplay = new List<CitiesList>();
lstDisplay.AddRange(query);
return lstDisplay;
}
}
public class CountriesList
{
public int CountryId { get; set; }
public string CountryName { get; set; }
public List<CountriesList> GetDisplayCountryList()
{
//code
.
.
var query = from o in dsResult.Tables[0].AsEnumerable()
select new CountriesList
{
CountryName = o.Field<string>("CountryName"),
CountryId = o.Field<int>("CountryId")
}
}
All this code is working well....Now what if i want a join query to display data from both tables?because i can assign data only to one list at a tyme?
shafiqkr
Member
454 Points
372 Posts
Object Oriented Model Issue
Feb 16, 2012 12:15 PM|LINK
i have two tables
1= cities(cityId,CITY(string) ,CountryId)
2= countries(Id,CountryName(string))
i have two classes
public class CitiesList { public int cityId{ get; set; } public int CountryId{ get; set; } public string CITY { get; set; } public List<CitiesList> GetCity() { //get city list . . . var query = from o in dsResult.Tables[0].AsEnumerable() select new CitiesList { CITYID = o.Field<int>("CITYID"), CITY = o.Field<string>("CITY") }; List<CitiesList> lstDisplay = new List<CitiesList>(); lstDisplay.AddRange(query); return lstDisplay; } } public class CountriesList { public int CountryId { get; set; } public string CountryName { get; set; } public List<CountriesList> GetDisplayCountryList() { //code . . var query = from o in dsResult.Tables[0].AsEnumerable() select new CountriesList { CountryName = o.Field<string>("CountryName"), CountryId = o.Field<int>("CountryId") } } All this code is working well....Now what if i want a join query to display data from both tables?because i can assign data only to one list at a tyme?shafiqkr
Member
454 Points
372 Posts
Re: Object Oriented Model Issue
Feb 29, 2012 05:44 AM|LINK
can i get data to display from both tables?
pratik_galor...
Participant
1483 Points
330 Posts
Re: Object Oriented Model Issue
Feb 29, 2012 05:53 AM|LINK
of course you can, dont set return type as a particular class of your function..keep it list only and join your tables with LINQ, like,
var type = from t1 in db.UserItems
join t2 in db.Items
on t1.ItemID equals t2.ID
where t1.ID == userItemID
select new { t1.ID, t2.CategoryType };
Software Engineer,
iGATE Global Solutions.
pratik_galoria@yahoo.co.in
+91-8905195943
shafiqkr
Member
454 Points
372 Posts
Re: Object Oriented Model Issue
Feb 29, 2012 10:29 AM|LINK
could not understand...please give me an example from my code above...
pratik_galor...
Participant
1483 Points
330 Posts
Re: Object Oriented Model Issue
Feb 29, 2012 11:08 AM|LINK
refer this link
http://msdn.microsoft.com/en-us/library/bb386921.aspx
Software Engineer,
iGATE Global Solutions.
pratik_galoria@yahoo.co.in
+91-8905195943
shafiqkr
Member
454 Points
372 Posts
Re: Object Oriented Model Issue
Feb 29, 2012 11:16 AM|LINK
Actually i am using one class for one table fields.so creating list of that class..
Now how i will call and use other table fields in this one class ?
one storeprocedure returns only one table as dataset...i can not get this point