Solved

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

Posted on 2013-12-30
1
369 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

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 …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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