Как выбрать записи из нескольких таблиц с максимальным значением счета из одной таблицы с помощью linq in ASP.NET MVC C#
I have 3 tables 1. Tbl_Model, 2. Tbl_ModelImg, 3.Tbl_Category what i want is to fetch the records from these 3 tables on behalf of categoryId. The single model may have multiple images, but i want to show all products of that category with their images. The problem is i want only single image in that view. so that when a user click on that particular model, the details of that model and all its images will show on next view. The following query is working fine but it displays all the images with their model name. Means If a model have 4 images than on categorydetails page it display 4 items with the same name and different images. here is the model class :
Что я уже пробовал:
public class showdata { public Tbl_ModelImg tmi { get; set; } public Tbl_Model tm { get; set; } public Tbl_SubCategory tblsubcategory { get; set; } }
public ActionResult Categorydetails(string sid) { var sId = Int64.Parse(new StandardModule().Decrypt(HttpUtility.UrlDecode(sid.ToString()))); try { var query = (from c in db.Tbl_Model join o in db.Tbl_ModelImg on c.Model_Id equals o.Model_Id join d in db.Tbl_SubCategory on c.SubCategory_Id equals d.Id where c.SubCategory_Id == sId select new showdata() { tm = c, tmi = o, tblsubcategory = d }).OrderByDescending(d => d.tm.Id).ToList(); var squery = (from c in db.Tbl_SubCategory where c.Id == sId select c).FirstOrDefault(); ViewBag.SubcategoryName = squery.SubCategory_Name; return View(query); } catch(exception e) { Response.Write(e.Message); } }