tags:

views:

51

answers:

2

I have a LINQ to SQL class that I am reading into a List.

When reading in from the table, I get an error "String must be exactly 1 character long".

I have looked over the Table definition for this file, and the .dbml file for this table, and there is no field that is exactly 1 char long.

The table (a legacy table) has a lot of fields. How can I easily determine which field that is causing the problem?

Thank you.

+1  A: 

Unfortunately, the error does not contain anything helpful to indicate which column failed in the insert. The best solution I have is to turn on profiling on your SQL box. Then you can inspect the SQL that actually got sent to the server. With that, and a lot of trial and error, you can probably find which column is throwing the error.

You may want to look at decorating your class with System.ComponentModel.DataAnnotations (and its related attributes), and validating that the SQL will pass before it gets sent to the server. A hassle? Yes. But usable error codes and very, very valuable.

Jarrett Meyer
Thanks for the usggestions - but I have the feeling that the problem is not with the SQL query but with the conversion from the data returned to the LINQ class. I think I might implement your suggestion anyways, because as you have noted (and I strongly agree) usable error codes are very very valuable :)
Larry Watanabe
+1  A: 

I figured out a reasonable (though not automated) approach - do a binary search on the columns by deleting half the columns from the LINQ .dbml file (can be done with mouseclicks and shift for multiple selection) and then running program.

Once down to about 5 entries, do linear search (because of overhead of click-copy paste for a new table, overhead of binary search means linear search is better for size N. The actual number depends on your application).

This narrowed it down to the problematic column in about 10 minutes.

Larry Watanabe
I've used that interolation technique a lot. We learned it in math when I was young and had to learn to use a slide rule. Boy does that age me!
HLGEM