The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

HowTo: Return Table PK (GUID) after AddNew

Last post 08-13-2007, 4:12 PM by bizsoft. 3 replies.
Sort Posts: Previous Next
  •  08-12-2007, 9:39 PM 4492

    HowTo: Return Table PK (GUID) after AddNew

    How is the identity of the inserted row accessed after using a AddNew?

    Code below inserts aok, but when I try to access in this case _order.OrderID it is NULL after the insert.

    Does the AddNew update the Object?? My VistaDB has the OrderID set to have a default value of newid() and is the Primary Key..

    Code:
                        Dim _order As New Order
                        _order.AddNew()
                        'Create NEW ORDER ID
                        Dim _CustomerID As System.Guid = New System.Guid(Me.CustomerID)
                        Dim _SalesRepID As System.Guid = New System.Guid(Common.Values.SalesRepID)
                        _order.CustomerID = _CustomerID
                        _order.SalesRepID = _SalesRepID
                        _order.OrderDate = Now
                        _order.DateSynced = Nothing
                        _order.Notes = Me.txtNotes.Text
                        _order.Signature = Helper.Utils.ConvertImageToByteArray(Me.inkSignature.Image, System.Drawing.Imaging.ImageFormat.Gif)
                        _order.NexusImport = False
                        _order.Save()
  •  08-13-2007, 5:30 AM 4494 in reply to 4492

    Re: HowTo: Return Table PK (GUID) after AddNew

    Exactly as you'd hope it would work. Btw, you don't have to call AddNew() any longer on single objects, it will be done behind the scenes for you.

    Code:
    Dim _order As New Order
    _order.Somefield = "wow"
    _order.Save()
    
    ' After a call to Save, _order.OrderID is filled in 

     

     


    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  08-13-2007, 5:32 AM 4495 in reply to 4494

    Re: HowTo: Return Table PK (GUID) after AddNew

    Ooops, also set your defaut to GUID() we didn't know that VistaDB supported newid(), we are fixing that on the next release, but it should work with GUID()
    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  08-13-2007, 4:12 PM 4507 in reply to 4495

    Re: HowTo: Return Table PK (GUID) after AddNew

    Cheers.

     Definitly doesn't work with newid() as default vale in VistaDB. Will wait for next release but until then will change it to GUID().

View as RSS news feed in XML