locked
Object Oriented Model Issue RRS feed

  • Question

  • User-937748457 posted

    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?

    Thursday, February 16, 2012 8:15 AM

All replies

  • User-937748457 posted

    can i get data to display from both tables?

    Wednesday, February 29, 2012 1:44 AM
  • User-1604169926 posted

    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 };

    Wednesday, February 29, 2012 1:53 AM
  • User-937748457 posted

    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,

    could not understand...please give me an example from my code above...

    Wednesday, February 29, 2012 6:29 AM
  • User-1604169926 posted

    refer this link

    http://msdn.microsoft.com/en-us/library/bb386921.aspx

    Wednesday, February 29, 2012 7:08 AM
  • User-937748457 posted

    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

    Wednesday, February 29, 2012 7:16 AM