0

Is it possible to use inner join on tables with linq, and put the value in a list so i can place it in a webgrid?

Little code i want to add another table to the linq and fill the rest so i can show it on the view !

        List<vakantieList> Freedayslist = new List<vakantieList>();
        /*Create instance of entity model*/
        GemeenteLeerdanEntities2 db = new GemeenteLeerdanEntities2();

        var result = (from data in db.Freedays 
                              select data);
        foreach (var item in result)
        {
            Freedayslist.Add(new vakantieList
            {
                FreeDaysID = item.FreeDaysID,
                BSN = item.BSN,
                FirstName = item.FirstName,
                LastName = item.LastName,
                TotalDays = item.TotalDays,
                DaysUsed = item.DaysUsed,
                DaysRemaining = item.DaysRemaining,
                PersonalID = item.PersonalID,
            });
        }
John Saunders
  • 160,644
  • 26
  • 247
  • 397
Okkie
  • 327
  • 1
  • 8

1 Answers1

0

Yes, Inner joins are possible in LINQ, have a look at the documentation.

But, in your case, you don't need an inner join, you simply need to fill your custom list, and you can directly do that in LINQ query without separate foreach loop.

Try this:-

List<vakantieList> = (from data in db.Freedays
             select new vakantieList
             {
                FreeDaysID = data.FreeDaysID,
                BSN = data.BSN,
                FirstName = data.FirstName,
                LastName = data.LastName,
                TotalDays = data.TotalDays,
                DaysUsed = data.DaysUsed,
                DaysRemaining = data.DaysRemaining,
                PersonalID = data.PersonalID,
            }).ToList();
Rahul Singh
  • 21,585
  • 6
  • 41
  • 56
  • Do i need to add the second table in the same list also and then add it to the webgrid ? – Okkie Dec 11 '14 at 11:43
  • @OktayAltay - Where is your second table? You didn't mentioned. Yes you can join both and fill your custom list `vakantieList`. – Rahul Singh Dec 11 '14 at 11:44