Bug in nvarchar(1) conversion in DataContext designerHello all,<div><br></div><div>I have some tables which use nvarchar(1) nullable fields. This gets translated on the LINQ entity (using the Visual Studio generator and dragging a table from the server explorer to the datacontext) to nullable char (&quot;char?&quot;) properties for the entities, which might look correct at first glance, however, nvarchar(1) allows for empty strings, which char? doesn't, and LINQ will choke on any query with such field data.</div><div><br></div><div>The workaround is a matter of making it a System.String on the entity, but it should be noted that nvarchar(1) entities are not necessarily one char in length or null (they can contain empty strings). In my application (made in Delphi, and currently making a port over to ASP.NET) this has caused a bunch of headaches, since some of those fields do mean different things with empty and null data for the application.</div><div><br></div><div>Don't know if this should go on this forum though, it's not a bug with Linq per-se, but rather with the DataContext designer (and maybe SQL Metal? haven't tried it)</div><hr class=sig>Before I speak, I have something important to say.© 2009 Microsoft Corporation. All rights reserved.Thu, 05 Feb 2009 23:20:45 Zac91e587-6e91-454c-9fa2-bab20b7a258chttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/ac91e587-6e91-454c-9fa2-bab20b7a258c#ac91e587-6e91-454c-9fa2-bab20b7a258chttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/ac91e587-6e91-454c-9fa2-bab20b7a258c#ac91e587-6e91-454c-9fa2-bab20b7a258cJavier Camposhttp://social.msdn.microsoft.com/Profile/en-US/?user=Javier%20CamposBug in nvarchar(1) conversion in DataContext designerHello all,<div><br></div><div>I have some tables which use nvarchar(1) nullable fields. This gets translated on the LINQ entity (using the Visual Studio generator and dragging a table from the server explorer to the datacontext) to nullable char (&quot;char?&quot;) properties for the entities, which might look correct at first glance, however, nvarchar(1) allows for empty strings, which char? doesn't, and LINQ will choke on any query with such field data.</div><div><br></div><div>The workaround is a matter of making it a System.String on the entity, but it should be noted that nvarchar(1) entities are not necessarily one char in length or null (they can contain empty strings). In my application (made in Delphi, and currently making a port over to ASP.NET) this has caused a bunch of headaches, since some of those fields do mean different things with empty and null data for the application.</div><div><br></div><div>Don't know if this should go on this forum though, it's not a bug with Linq per-se, but rather with the DataContext designer (and maybe SQL Metal? haven't tried it)</div><hr class=sig>Before I speak, I have something important to say.Thu, 08 Jan 2009 00:51:09 Z2009-01-08T00:53:40Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/ac91e587-6e91-454c-9fa2-bab20b7a258c#c0da3d92-9d44-4f99-bc34-51c06425f658http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/ac91e587-6e91-454c-9fa2-bab20b7a258c#c0da3d92-9d44-4f99-bc34-51c06425f658KristoferA - Huagati Systemshttp://social.msdn.microsoft.com/Profile/en-US/?user=KristoferA%20-%20Huagati%20SystemsBug in nvarchar(1) conversion in DataContext designer Hi Javier,<br><br>I have an add-in for VS2008 that adds a bunch of features to the L2S designer. One of those features is a menu that syncs the model with the underlying database. As of ver 1.56* (the latest version) it will map nvarchar(1) and varchar(1) to System.String instead of <font style="font-size:10px">[as per the designer default]</font> System.Char.  <font color="#999999"><em>(* = Earlier versions of the add-in used the same type mapping as the designer, but as you correctly point out, using Char for nvarchar(1)/varchar(1) can result in errors for zero length strings)</em></font><br><br>You can download it and get a free trial license from <a href="http://www.huagati.com/dbmltools/">http://www.huagati.com/dbmltools/</a><br><br>Best regards,<br>KristoferThu, 08 Jan 2009 09:00:51 Z2009-01-08T09:00:51Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/ac91e587-6e91-454c-9fa2-bab20b7a258c#0ab7b564-de8b-4b4a-a5a6-77f9a43dee0dhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/ac91e587-6e91-454c-9fa2-bab20b7a258c#0ab7b564-de8b-4b4a-a5a6-77f9a43dee0dJavier Camposhttp://social.msdn.microsoft.com/Profile/en-US/?user=Javier%20CamposBug in nvarchar(1) conversion in DataContext designerI'm gonna try it. Thanks a lot!<hr class="sig">Before I speak, I have something important to say.Thu, 08 Jan 2009 09:23:56 Z2009-01-08T09:23:56Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/ac91e587-6e91-454c-9fa2-bab20b7a258c#2f73dd27-fe88-4da5-8b2f-50d354c73c5ehttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/ac91e587-6e91-454c-9fa2-bab20b7a258c#2f73dd27-fe88-4da5-8b2f-50d354c73c5eJavier Camposhttp://social.msdn.microsoft.com/Profile/en-US/?user=Javier%20CamposBug in nvarchar(1) conversion in DataContext designerWow, I love the addon, I was doing really wicked stuff with Sql Metal to update my datacontext's (the update tool was supposed to come with VS2008 SP1, but didn't) ... I will try to get my boss to buy it for me :-)<div><br></div><div>Thanks a lot!</div><hr class="sig">Before I speak, I have something important to say.Thu, 08 Jan 2009 09:42:18 Z2009-01-08T09:42:18Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/ac91e587-6e91-454c-9fa2-bab20b7a258c#c3a7574f-29ae-43f3-a01c-6e83390c5735http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/ac91e587-6e91-454c-9fa2-bab20b7a258c#c3a7574f-29ae-43f3-a01c-6e83390c5735KristoferA - Huagati Systemshttp://social.msdn.microsoft.com/Profile/en-US/?user=KristoferA%20-%20Huagati%20SystemsBug in nvarchar(1) conversion in DataContext designer<div class=quote><font class=quoteHeader>Javier Campos said:</font> <p>Wow, I love the addon, I was doing really wicked stuff with Sql Metal to update my datacontext's (the update tool was supposed to come with VS2008 SP1, but didn't) ... I will try to get my boss to buy it for me :-) <div><br></div> <div>Thanks a lot!</div> <hr class=sig> Before I speak, I have something important to say. <p></p></div> <p><br><br>Hi Javier,</p> <p>Glad to hear that you like it! :)</p> <p>Best regards,<br>Kristofer</p>Tue, 27 Jan 2009 10:04:29 Z2009-01-27T10:04:29Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/ac91e587-6e91-454c-9fa2-bab20b7a258c#b6f25bfd-a6de-45e5-9024-b58715bd85cehttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/ac91e587-6e91-454c-9fa2-bab20b7a258c#b6f25bfd-a6de-45e5-9024-b58715bd85ceSarah Parra - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Sarah%20Parra%20-%20MSFTBug in nvarchar(1) conversion in DataContext designer<p> SQLMetal actually does generate the varchar(1) as String, so that is a workaround as well, if anyone else is running into this. We also have a bug tracking fixing this in the O/R Designer for the next version of VS.</p> <p>Thanks,</p> <p>Sarah</p><hr class="sig">This posting is provided &quot;AS IS&quot; with no warranties, and confers no rights.Thu, 05 Feb 2009 23:20:32 Z2009-02-05T23:20:32Z