Linq, Json, Select product from db

I have 3 tables of Dish, Wine, Suggestion. Then the idea is to use the table suggestions table to put the dish and wine, of which one of them offers to each other. I am using LINQ, but when one product has no offer, it doesn't add to json.

var query = (from m in db.Dish
            join t in db.TypeDish on m.idTypeDish equals t.idTypeDish
            join i in db.ImageDish on m.idDish equals i.idDish into g
            join s in db.Suggestion on m.idDish equals s.idDish
            join si in db.ImageWine on s.idWine equals si.idWine into f
            where m.idTypeDish == dish

            select new DishModel()
            {
                Name = m.name,
                CalorificValue = m.calorificValue,
                Price = m.price,
                ShortName = m.shortName,
                Time = m.manufactureTime,
                Description = m.description,
                UrlImageList = g.Select(i => _url + i.Image.urlImage).ToList(),
                BeveragesList = new List<BeverageModel>()
                {
                    new BeverageModel()
                    {
                        Name = s.Wine.name,
                        ShortName =  s.Wine.shortName,
                        Price =  s.Wine.price,
                        Description = s.Wine.description,
                        AlcoholContent = s.Wine.alcoholContent,
                        WineEnum = WineEnum.WhiteWine,
                        Region =  s.Wine.Region.name,
                        WineCaste =  s.Wine.wineCaste,
                        UrlImageList = f.Select(i => _url+i.Image.urlImage).ToList(),
                    }
                }
            }).ToList();


        return query;

      

Now I have 2 items in the DB and it only sends one because the other has no offer. The error is probably related to unions, but I'm new to Linq.

Thank.

+3


source to share





All Articles