Specified Cast Is Not Valid |
![]() ![]() |
Specified Cast Is Not Valid |
Jun 5 2009, 06:47 AM
Post
#1
|
|
|
|
Hi,
I'm having a problem with my dbml, the problem occurs both in a compiled assembly (from VS) and by referencing my dbml in lingpad. I got the problem on two different properties. The first time it was a foreign key but now it's just a regular property. Whenever I call SubmitChanges() on my datacontext, I get a Specified cast is not valid. It is just a regular update. I checked my dbml and noticed that the server-type matched the actual column type in the database. Also, the code compiles and I'm passing the correct type to the property for the update. The error occurs before any SQL statement is generated. If I create a new dbml with just the subset of table I need for this update, everything seems to work fine. I also tried recreating my whole schema from scratch with the same tables... but the new schema has the same problem. Have you ever seen this problem? To me it looks like a bug in the dbml, but I have no way to find where and why. Thanks, David |
|
|
|
Jun 6 2009, 05:50 PM
Post
#2
|
|
|
Advanced Member ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 215 Joined: 15-February 08 From: Perth, Australia Member No.: 90 |
Does it also happen in LINQPad when you connect directly to the database?
If not, it's probably a problem in your dbml. A datatype for a column somewhere is invalid. Joe |
|
|
|
Jun 6 2009, 05:53 PM
Post
#3
|
|
|
Advanced Member ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 215 Joined: 15-February 08 From: Perth, Australia Member No.: 90 |
You could also try removing that table from the dbml in the designer, and then dragging it on again.
|
|
|
|
Jun 10 2009, 09:57 AM
Post
#4
|
|
|
|
I'm quite sure that the problem is in the dbml, as if I create a new one, with just the two tables I need, I do not have the problem.
Connection directly to the database from LINQpad works fine. The only real problem, is that recreating the dbml from scratch, adding all the same tables and keeping all the same fields ends up giving the same problem. I was just wondering if you've seen that before. David |
|
|
|
Jun 29 2009, 08:23 AM
Post
#5
|
|
|
|
Did you figure this error out? I am having the same problem and it's driving me crazy. I have a deadline and this error is holding me up. It has to be a bug. I just deleted and readded the table from my dbml, and have checked the column definitions in the database and the dbml. They match.
HELP! |
|
|
|
Jul 5 2009, 12:18 PM
Post
#6
|
|
|
|
Hi,
Sorry I haven't found the solution, tried a lot of stuff. I resorted to using db.ExecuteCommand/ExecuteQuery for some dynamic sql in the few places I was having problems. The way the parameters work is pretty neat. David edit: Also it seems the more table I add to my dbml the more of this issue creeps up in some fields. I'm about at 3 different fields now that have the issue. This post has been edited by xakor: Jul 5 2009, 12:20 PM |
|
|
|
Aug 22 2009, 10:23 PM
Post
#7
|
|
|
|
Can you tell me that only db.ExecuteCommand/ExecuteQuery is doing problems?
Or there is also another error which arises during the program? -------------------- Does Someone Do Medical Assistant Jobs like me? then please guide me to start a Medical Assistant Career.
|
|
|
|
Aug 23 2009, 07:56 AM
Post
#8
|
|
|
|
Hi, ExecuteCommand and ExcuteQuery have no problems... they are a work-around to the problem.
It seems that any table to have foreign keys/association on Char(X) fields might have the problem. For example, in my scenario, I have a table with 3 distinct associations using a Char(5) field, as soon as I remove two of the three association, I can then update using regular SubmitChanges() syntax. Also, after reading over some of the MS bug posts, it seems that this is an issue that has been fix, but unfortunately only for the .NET 4.0 which is not close by. One would hope that a hotfix is available but there doesn't seem to be any. David This post has been edited by xakor: Aug 23 2009, 07:57 AM |
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 22nd November 2009 - 11:47 PM |