Link to home
Start Free TrialLog in
Avatar of finance_teacher
finance_teacher

asked on

LINQ, C# -- easy "Generic.List" fix ?

Below "var genres" WORKS, displaying the attached.
How can I get the below "var genres2" to display a LIST ?

When I run, a
Cannot implicitly convert type 'System.Linq.IQueryable<System.Collections.Generic.List<char>>' to 'System.Collections.Generic.List<string>'. An explicit conversion exists (are you missing a cast?) error displays.

The "PartNumber" database column is varchar(50)
------------------------------------------------------------------------------------
   public ActionResult Index()
        {
            var genres = new List<string> { "Rock", "Jazz", "Country", "Pop", "Hip", "Disco" };

            var genres2 = from o in db.Lookup_PartNumbers
                          select o.PartNumber.ToList();

            // Create our view model
            var viewModel2 = new StoreIndexViewModel
            {
                NumberOfGenres = genres.Count(),
                Genres = genres,
                Test = genres.Count()
            };

            return this.View(viewModel2);          
        }
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial