Menu

uniqueidentifier primary keys in MSSQL 2000

ian r
2005-04-19
2013-03-07
  • ian r

    ian r - 2005-04-19

    How do I define my classes and mapping file so that I can map to tables that use a 'uniqueidentifier' (guid) as a Primary Key in MS SQL 2000?

    The FAQ mentions how to use guids, but only shows how to map them to string fields in the database.

    When I try it with uniqueidentifier columns I get 'Invalid cast from System.String to System.GUID' errors

     
    • Richard Banks

      Richard Banks - 2005-04-20

      I'll have to check this (I thought it was working for 2.2 RC1)

      - Richard

       
    • ian r

      ian r - 2005-04-21

      ah, good point
      I am on 2.0.1
      I will try 2.2 RC1

       
    • ian r

      ian r - 2005-04-21

      Nope still doesn't work with 2.2.RC1

      I am trying to map the built in GuidValue to the uniqueidentifier primary key. However GuidValue is a 'string' and I guess that is where the problem lies.

      Full error message:
      AtomsFramework.RetrieveException : Invalid cast from System.String to System.Guid.
      Inner Exception message : Invalid cast from System.String to System.Guid.

      at AtomsFramework.PersistenceBroker.RetrieveObject(IPersistableObject& obj, Boolean useFind, Boolean useCache) in C:\Projects\sourceforge\dotnet 2.2\CPersistenceBroker.vb:line 200
         at AtomsFramework.PersistentObject.Retrieve(PersistentObject& obj, Boolean useCache) in C:\Projects\sourceforge\dotnet 2.2\CPersistentObject.vb:line 834
         at AtomsFramework.PersistentObject.Retrieve(PersistentObject& obj) in C:\Projects\sourceforge\dotnet 2.2\CPersistentObject.vb:line 855
         at AtomsFramework.PersistentObject.Retrieve() in C:\Projects\sourceforge\dotnet 2.2\CPersistentObject.vb:line 882
         at AtomsDemo1.GeneralTest.FetchIndividual() in c:\inetpub\wwwroot\atomsdemo1\generaltest.cs:line 39

       
      • Richard Banks

        Richard Banks - 2005-04-21

        Hi Ian,

        I don't have an SQL server handy at the moment to try it, but I've committed a few changes that *should* fix things.

        Basically the changes are in the MSSQL provider where parameter values are set, and also in the PersistentObject and InjectedObject in SetAttributeValue.

        You'll need to get the latest code from CVS (which is normally available about 5 hours after I commit changes)

        Let me know how you go.

        - Richard.

         

Log in to post a comment.