Le réseau pour les développeurs > Forums - Accueil > LINQ to SQL > Bug in nvarchar(1) conversion in DataContext designer
Poser une questionPoser une question
 

TraitéeBug in nvarchar(1) conversion in DataContext designer

  • jeudi 8 janvier 2009 00:51Javier Campos Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    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.

Réponses

  • jeudi 5 février 2009 23:20Sarah Parra - MSFTModérateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     Traitée

    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.

Toutes les réponses

  • jeudi 8 janvier 2009 09:00KristoferA - Huagati SystemsAuteur de réponseMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    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
  • jeudi 8 janvier 2009 09:23Javier Campos Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    I'm gonna try it. Thanks a lot!
    Before I speak, I have something important to say.
  • jeudi 8 janvier 2009 09:42Javier Campos Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    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.
  • mardi 27 janvier 2009 10:04KristoferA - Huagati SystemsAuteur de réponseMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    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

  • jeudi 5 février 2009 23:20Sarah Parra - MSFTModérateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     Traitée

    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.