Microsoft Developer Network > 포럼 홈 > LINQ to SQL > Bug in nvarchar(1) conversion in DataContext designer
질문하기질문하기
 

답변됨Bug in nvarchar(1) conversion in DataContext designer

  • 2009년 1월 8일 목요일 오전 12:51Javier Campos 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Hello all,

    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 ("char?") 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.

    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.

    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)

    Before I speak, I have something important to say.

답변

  • 2009년 2월 5일 목요일 오후 11:20Sarah Parra - MSFT중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    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.

    Thanks,

    Sarah


    This posting is provided "AS IS" with no warranties, and confers no rights.

모든 응답

  • 2009년 1월 8일 목요일 오전 9:00KristoferA - Huagati Systems답변자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Hi Javier,

    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 [as per the designer default] System.Char.  (* = 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)

    You can download it and get a free trial license from http://www.huagati.com/dbmltools/

    Best regards,
    Kristofer
  • 2009년 1월 8일 목요일 오전 9:23Javier Campos 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    I'm gonna try it. Thanks a lot!
    Before I speak, I have something important to say.
  • 2009년 1월 8일 목요일 오전 9:42Javier Campos 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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 :-)

    Thanks a lot!

    Before I speak, I have something important to say.
  • 2009년 1월 27일 화요일 오전 10:04KristoferA - Huagati Systems답변자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Javier Campos said:

    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 :-)


    Thanks a lot!

    Before I speak, I have something important to say.



    Hi Javier,

    Glad to hear that you like it! :)

    Best regards,
    Kristofer

  • 2009년 2월 5일 목요일 오후 11:20Sarah Parra - MSFT중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    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.

    Thanks,

    Sarah


    This posting is provided "AS IS" with no warranties, and confers no rights.