In a Win7 application, I am trying to update several fields in an ADO.NET database table called "Channel" named EntitySetMapping "Channels", using EntityClient in EF to access SqlServerCe 3.5 (IPManager_DBEntities).
In VSE ID 2010, the code compiles fine, and Intellisense has no complaints. The format of the datatable data channel is referenced below, since the various fields in the line (selected on the Number channel) need to be updated with the information passed to it from code that is not shown for simplicity. None of the things I've been looking for on Google in the last few days solved my Casting dilemma. Using LINQ, I get this RunTime exception:
"Cannot pass an object of type 'System.Data.Objects.ObjectQuery`1 [Manager.Data.Channel]' to enter '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 that will help me in this predicament.
David source share