0

I'm trying to build a list of software names from db.tblSoftwares by using a query.

I've tried to use .Add method and it will not work.

Any suggestions would be appreciated.

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);
}
Dominic Zukiewicz
  • 8,258
  • 8
  • 43
  • 61
TerryB
  • 1
  • 1
  • 2
  • I posted before I asked the question: I'm sure there is a better way at doing this but this was the best I could understand to do. I'm trying to build a list of software names from db.tblSoftwares by using a query. I've tried to use .add method and it will not work. Any suggestions would be appreciated. thanks.. – TerryB Dec 17 '12 at 22:42

1 Answers1

0

Join the two tables and select the new list directly.

try this: C# Joins/Where with Linq and Lambda

Community
  • 1
  • 1
Winter Winter
  • 173
  • 2
  • 11