Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6546217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:40:53+00:00 2026-05-25T11:40:53+00:00

it will give me error Unable to cast object of type . public class

  • 0

it will give me error Unable to cast object of type.

  public class CusInfomration
   {
      public string CustomerName { get; set; }
      public string CustomerID { get; set; }
      public string OrderDate { get; set; }
      public string OrderId { get; set; }
   }

  var CustomerFromWash =  from p in _NorthWindDataContext.Customers
                          join q in _NorthWindDataContext.Orders 
                          on p.CustomerID   equals q.CustomerID
                          where p.Region == "WA"
                          select new
                         {                                                   
                             CustomerName =Convert.ToString(p.CompanyName),
                             CustomerID = Convert.ToString(p.CustomerID),
                             OrderId = Convert.ToString(q.OrderID),
                             OrderDate = Convert.ToString(q.OrderDate),
                          };

  List<cusinfomration> lstCust = (List<cusinfomration>)CustomerFromWash;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:40:54+00:00Added an answer on May 25, 2026 at 11:40 am

    That LINQ query returns an IQueryable<T>. IQueryable<T> is an interface and List<T> does not implement it, so there is no way that the underlying, concrete implementation is a List<T> (it does however implement IEnumerable<T>, so a cast to that would be valid). Even if it were it would not be a safe cast to make as the .NET folks may want to change out the underlying implementation someday and your cast would be broken. Not a good idea even if it did work initially.

    You can call ToList() on the return value of the LINQ query:

    var CustomerFromWash = (from p in _NorthWindDataContext.Customers
                            join q in _NorthWindDataContext.Orders 
                            on p.CustomerID   equals q.CustomerID
                            where p.Region == "WA"
                            select new
                            {                                                   
                               CustomerName =Convert.ToString(p.CompanyName),
                               CustomerID = Convert.ToString(p.CustomerID),
                               OrderId = Convert.ToString(q.OrderID),
                               OrderDate = Convert.ToString(q.OrderDate),
                            }).ToList();
    

    Even then though you are selecting a collection of anonymous types, not CustInformation objects. If you want CustInformation objects to be returned then you will need to:

    select new CustInformation 
    {
        // set properties here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

AssemblyName.GetAssemblyName().Version.ToString() will give the version number ,,but i need to get version number from
my Mysql cannot connect remotly,it will give error 2003. I am using Ubuntu 11.04,
On this coderanch link, I found that the following comment will give compiler error
I get this error when I call map.AddPopup() in OpenLayers: Unable to get value
The code bellow will give compile error on line enum en = A::en; but
to_friend = User.objects.filter(username=friend_q)[0:1] If 'friend_q' is NOT inside the User.username...it will give error. What
like JSON.parse('{text: ~#}'); will give synatax error, because there is 0x0B between ~ and
From php.net: <html> <?php /* This will give an error. Note the output *
i will give an example of the problem i have. My XML is like
Which ORM will give me compile-tested queries? Is linqtosql compile time tested? Edit: Say

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.