c# - Get multiple data from tables Using Entity Framework -


public actionresult hotel_read(string text) {     var result = gethotel().where(c => c.name.contains(text) || c.city.contains(text) || c.country.contains(text)).tolist();     return json(result, jsonrequestbehavior.allowget); }  private static ienumerable<hotelviewmodel> gethotel() {     using (travelagancyentities1 db = new travelagancyentities1())     {         var query = db.hotels                       .include(p => p.city.country).distinct().tolist();          return query.select(hotel => new hotelviewmodel          {              name = hotel.name,              city = hotel.city.city_name,     **line 10-** country = hotel.city.country.country_name,//!!!           });     } } 

when run code without line 10, working successfully, when code run with line 10, it's not working.

enter image description here

i assume code should run properly. thing makes me suspicious, trying retrieve hotel table data plus 2 other table(with include)
try :

var q = (from x in db.hotels.include(c => c.city).include(c =>  c.city.country)                          x.id == 5030                          select x).distinct().tolist(); string s = q[0].city.country.country_name; 

limit select where clause.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -