Microsoft LINQ Books

Programming Microsoft LINQ & Introducing Microsoft LINQ
Welcome to Microsoft LINQ Books Sign in | Join | Help
in Search

Marco Russo

LINQ to SQL and varchar(1) fields

If you are using the Object Relational Designer of LINQ to SQL creating an entity of an existing table that has some VARCHAR(1) fields, you are going into this issue.

The data member created in C# is char instead of string. If the field is always filled with one char, this works. But if you try to read a row from the table containing an empty string (not a NULL field, but a field of zero characters) you will get this exception:

String must be exactly one character long.

This behavior has been already described in this post and in the LINQ forum. But one more warning could be important: this is a latent error that will express yourself only at runtime if you don't fix. Thus, be careful whenever you have some VARCHAR(1) fields in your tables.

Published giovedì 17 luglio 2008 18.03 by Marco.Russo

Comments

 

Marco Russo said:

Recentemente ho scritto alcuni post in inglese nel mio blog su LINQ: Campi varchar(1) usando LINQ to

luglio 20, 2008 10.25
Anonymous comments are disabled
Powered by Community Server (Personal Edition), by Telligent Systems