0

我正在尝试db.tblSoftwares通过使用查询来构建软件名称列表。

我尝试过使用.Add方法,但它不起作用。

任何建议,将不胜感激。

public ActionResult Details(int id)
{
   // this gets the hostname based on id//
   tblComputer tblcomputer = db.tblComputers.Find(id);
   var workstation  = tblcomputer.HostName;

   // next want to get the list of software names assigned to host name//

   // get the list of licenses for hostname based on id/
   var Licenses = (from n in db.tblLicenses
                   where n.tblComputerComputerId == id
                   select n.tblSoftwareSoftwareId).ToList();

   List<string> appslist = new List<string>();

   foreach (var l in Licenses)
   {
       var query1 = (from s in db.tblSoftwares
                     where s.SoftwareId == l
                     select new { s.Name }).ToList();

       // appslist = query1;           
   }                         

   var swList = new List<string> { "Adobe", "MS Office", "MS Visio" };

   var ViewModel = new ComputerSoftwareViewModel
   {
       HostName = workstation,
       Applications = swList                
   };

   return View(ViewModel);
}
4

1 回答 1

0

加入两个表并直接选择新列表。

试试这个: C# Joins/Where with Linq and Lambda

于 2012-12-17T22:55:47.230 回答