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.
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
Post a Comment