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<Sy stem.Colle ctions.Gen eric.List< char>>' to 'System.Collections.Generi c.List<str ing>'. 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);
}
How can I get the below "var genres2" to display a LIST ?
When I run, a
Cannot implicitly convert type 'System.Linq.IQueryable<Sy
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.