内部连接linq到webgrid

时间:2014-12-10 23:29:00

标签: linq

是否可以在带有linq的表上使用内连接,并将值放在列表中,以便将其放在webgrid中?

小代码我想在linq中添加另一个表并填充其余的表,以便我可以在视图上显示它!

        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,
            });
        }

1 个答案:

答案 0 :(得分:0)

是的,在LINQ中可以进行内连接,看一下documentation

但是,在您的情况下,您不需要内部联接,只需填写自定义列表,您就可以直接在LINQ查询中执行此操作而无需单独的foreach循环。登记/> 试试这个: -

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();