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 8621711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:52:48+00:00 2026-06-12T06:52:48+00:00

In a Win7 app, I am trying to update several fields in an ADO.NET

  • 0

In a Win7 app, I am trying to update several fields in an ADO.NET database table called “Channel”, with an EntitySetMapping Name of “Channels”, using EntityClient in the EF to access SqlServerCe 3.5 (IPManager_DBEntities).

With the VS 2010 IDE, the code compiles fine and Intellisense has no complaints. The format of the Channel datatable is referenced at the bottom as the various fields in a row (selected by Channel “Number”) need to be updated with information passed to it from code which is not shown for the sake of simplicity. Nothing I have Googled during the past several days has solved my Type Casting dilemma. Using LINQ, I get this RunTime Exception:

“Unable to cast object of type ‘System.Data.Objects.ObjectQuery`1 [Manager.Data.Channel]’ to type ‘Manager.Data.Channel'”.

    // Update channel status with information parsed from the data packet.
    using (IPManager_DBEntities context = new IPManager_DBEntities())
    {
        Channel thisChannelRow = (Channel)(from CE
                                             in context.Channels
                                          where CE. Number == int.Parse(IDLine[2])
                                         select CE);

        // Throwing exception after setting up this query:
        //   "Unable to cast object of type 'System.Data.Objects.ObjectQuery`1
        //   [Manager.Data.Channel]' to type 'Manager.Data.Channel'"
        //  During debug sessions, "thisChannelRow" is null as a result.

        MessageBox.Show("thisChannelRow. Channel = " + thisChannelRow.Number );

            ThisChannel.StatusID = int.Parse(IDLine[5]);
            ThisChannel.Cycle = int.Parse(IDLine[4]);
            ThisChannel.Modified = DateTime.Now;
            context.SaveChanges();
     }

I hope someone has a solution to help me through this predicament.

  • 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-06-12T06:52:49+00:00Added an answer on June 12, 2026 at 6:52 am

    The LINQ query is returning an object of a type descendant from IEnumerable<T>, not Channel, even if there is just one item in the sequence. To get the actual item, use FirstOrDefault:

    Channel thisChannelRow = (Channel)(from CE
                                       in context.Channels
                                       where CE. Number == int.Parse(IDLine[2])
                                       select CE).FirstOrDefault();
    

    Or First, Single, or SingleOrDefault if any of those are a better fit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to set up a web app (32bit on ii7/win7, 32bit setting is
VC++ 2008, CLR Console App, being developed under win7 x64. I'm using .net with
Trying to run a self-hosted app on my Win 7 system, with little success.
I downloaded the PhotoView reference app for Win7 with source. The app works, but
I wrote a WinForms app using .Net and C#. The app accesses DirectoryServices and
I'm trying to run an android app from eclipse on my device (moto droid2).
I'm trying to investigate why would my app, written in VC 2008, crash on
I'm writing this app via phonegap through eclipse on win7. I've declared a viewport
I'm having a lot of trouble trying to compile a resource file (file name
I been trying to get my WP7 app on the marked, but it is

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.