C# 3.0 in a Nutshell
C# 3.0 in a Nutshell, Third Edition A Desktop Quick Reference By Joseph Albahari, Ben Albahari
September 2007
Pages: 858


Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
Specified Cast Is Not Valid
xakor
post Jun 5 2009, 06:47 AM
Post #1


Active Member
***

Group: Members
Posts: 56
Joined: 27-November 08
From: Montreal
Member No.: 1,637



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
Go to the top of the page
 
+Quote Post
JoeAlbahari
post 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
Go to the top of the page
 
+Quote Post
JoeAlbahari
post 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.
Go to the top of the page
 
+Quote Post
xakor
post Jun 10 2009, 09:57 AM
Post #4


Active Member
***

Group: Members
Posts: 56
Joined: 27-November 08
From: Montreal
Member No.: 1,637



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
Go to the top of the page
 
+Quote Post
versute
post Jun 29 2009, 08:23 AM
Post #5


New Member
*

Group: Members
Posts: 1
Joined: 29-June 09
Member No.: 18,919



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!
Go to the top of the page
 
+Quote Post
xakor
post Jul 5 2009, 12:18 PM
Post #6


Active Member
***

Group: Members
Posts: 56
Joined: 27-November 08
From: Montreal
Member No.: 1,637



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
Go to the top of the page
 
+Quote Post
Seemi
post Aug 22 2009, 10:23 PM
Post #7


Active Member
**

Group: Members
Posts: 20
Joined: 21-August 09
Member No.: 19,829



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.
Go to the top of the page
 
+Quote Post
xakor
post Aug 23 2009, 07:56 AM
Post #8


Active Member
***

Group: Members
Posts: 56
Joined: 27-November 08
From: Montreal
Member No.: 1,637



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
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 22nd November 2009 - 11:47 PM