Mark Tabor

Mark Tabor

  • 551
  • 2k
  • 453.6k

Inner join using Linq

Feb 24 2022 6:16 PM

Hi  i have two tables 

Country (id,name)

City(id,Country_Id,CityName) 

Now when I am adding Record to country table , it is now showing on index view unless until I add a city with that country as well below is my controller linq query.

var test1 = (from c in db.Countries
                   join cc in db.Cities
                       on c.Id equals cc.Country_Id

                   select new
                   {
                     Id = c.Id,
                     CountryName = c.CountryName,
                     Code = c.Code,
                     IsActive = c.IsActive,

                     // IsActive = g.IsActive,
                     Date_Created = c.Date_Created,
                     Date_Modified = c.Date_Modified,

                   }).ToList();
      return Json(new { data = test1 }, JsonRequestBehavior.AllowGet);
    }


Answers (3)