SubSonic Forums
All Your Database Are Belong To Us

Starting A New Record In SubSonic 2.1 (VB ActiveRecord)

Latest post 08-19-2008 10:47 AM by kevinw. 4 replies.
  • 08-18-2008 10:47 AM

    Starting A New Record In SubSonic 2.1 (VB ActiveRecord)

     Has the behaviour changed between SS 2.0.3 and 2.1 wrt starting a new record.  In 2.0.3 one could just call the constructor without passing a parameter and get an empty record back.  In 2.1, this seems to return Nothing.  In 2.1, using VB.NET, how can I successfully start a new record?

    Kevin

  • 08-18-2008 3:14 PM In reply to

    Re: Starting A New Record In SubSonic 2.1 (VB ActiveRecord)

    This doesn't work?
    Dim tblName As New TableName()

    If I am I because I am I, and You are You because You are You, then I am I, and you are you. But If I am I because You are You, and You are You because I am I, then I am not I and You are not You. -Rabbi of Kotzk

  • 08-19-2008 5:45 AM In reply to

    Re: Starting A New Record In SubSonic 2.1 (VB ActiveRecord)

     Sorry, perhaps I didn't explain myself too well.  I have created a separate DAL with SubStage, and am trying to create a BLL to wrap the CRUD functions with error handling, then calling this BLL in a Windows form.  All VS2005 SP1 VB.NET.

    In the header of the BLL class I have a Public ioDAL As New BLLName.DALNameSpace.tableName, and wish to resue this throughout.  I have then created a NewRecord() method, in which I want to create an ioDAL item with empty fields.  I have tried two basic ways to do this without success:

    1. Call FetchByID() with an invalid PK value.  In SS2.0.3 this would give me my empty item.  However, in 2.1 if you trace it through the FetchByIdInternal() method in the ReadOnlyRecord.cs class returns null (Nothing in VB.NET).

    2. Re-Dim'ed the class to ioDAL as suggested.  Tracing this seems to give me what I want in the NewObject() method, but then drops it (? loses scope) when I get back to the calling form.

    Kevin

  • 08-19-2008 9:07 AM In reply to

    Re: Starting A New Record In SubSonic 2.1 (VB ActiveRecord)

    Kevin,

    I seem to recall reading somewhere a discussion on the changes to the "Key Not Found" behaviour change.
    Like you, I was using the previous behaviour in 2.03. Sad

    With regards to your "evaporating" object, what you are doing sounds very similar to the basics of my BO approach, and I havent experienced the issue you are describing. Although normally spread out over a couple of "layers", the console app below describes the nitty gritty of it, and it works. How is your approach different?

     

    Module Module1

        Sub Main()

            Dim _Order As Order = Factory.NewOrder()
            Console.WriteLine(" I got an Order For Customer " & _Order.CustomerID)
            Console.ReadLine()

        End Sub


    End Module


    Public Class Factory

        Public Function NewOrder() As Order
            Dim o As New Order()
            o.CustomerID = "AAAAA"
            Return o
        End Function

    End Class

  • 08-19-2008 10:47 AM In reply to

    Re: Starting A New Record In SubSonic 2.1 (VB ActiveRecord)

     Thanks for your feedback.  My BLL is slightly different in that it defines the ioDAL member on instantiation, and then it contains all of the methods (LoadRecord(), SaveRecord(), NewRecord(), etc).  In each case these work with the existing ioDAL member - or at least they do until my problems with creating a new record.  If have a sort of a fudge working now in that in NewRecord() I do

    loDAL = Dim....    ' creates a new local instance

    ioDAL = loDAL    ' assign the values to the main class member

    This seems to work, although I'm not sure as to whether there will be any side effects.

    Kevin

Page 1 of 1 (5 items) | RSS