Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-12-30
1
Medium Priority
?
377 Views
Last Modified: 2016-02-10
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);          
        }
0
Comment
Question by:finance_teacher
1 Comment
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 39746331
Try moving the ToList call outside of the LINQ query:

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

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question