Best Practice to Use Views or Tables with SQL Databases and BOs


Author
Message
Russell Scott Brown
Russell Scott Brown
StrataFrame User (424 reputation)StrataFrame User (424 reputation)StrataFrame User (424 reputation)StrataFrame User (424 reputation)StrataFrame User (424 reputation)StrataFrame User (424 reputation)StrataFrame User (424 reputation)StrataFrame User (424 reputation)StrataFrame User (424 reputation)
Group: Forum Members
Posts: 124, Visits: 597
Coming from a VFP and VPME background, I am wondering what is the best practice for applications that use SQL Databases.  In VFP applications I normally use Views for Forms and Reports and separate them into two or more databases.  Also, I would try to use Views instead of Filters most of the time.  Is the way I would do it in VFP still the best way for SQL database applications?

- Is it best to separate tables and views into separate databases?  I noticed the Strataflix and Strataframe samples both show views and tables together in the same DB but this may be just for simplification

- Should Maintenance Forms be based on views or tables?

- Should Reports use views or tables?

- When is it best to use a View as opposed to a table or a table with a filter?

- Also, I plan to develop applications using SF that I want to be able to sell just parts of as well as the entire application as a whole.  For example, I'm working on a Safety Review application that could be sold as a complete package or someone might just want to purchase the OSHA package, ADA package, Driver/Employee File package, Vehicle Inspections package, etc.  I might also have a Lite/Express version too for example.

- I'd be interested how others are doing it and what make the most sense in terms of flexibility, especially since I have the opportunity to start from "scratch" so to speak.

Thanks!

Russ Brown (Using C#2010/SQL Server 2008)

Replies
Ivan George Borges
Ivan George Borges
Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Hey Russel.

I think that a good time to use a view is when you need to use the BrowseDialog to search on different tables at the same time. So, if you have a form with a Parent BO and 1 or more Children BOs related, you could create a view to join all these tables and format the BrowseDialog to search on that view, so the user would get all the columns needed from the different tables. Once the BrowseDialog is Closed, you can deal with the view copying the data from the populated BO to another without duplicates on the Parent PK, get an array of the PKs populated and Fill your form Parent BO with the array of PKs you've just created.

I have found this a great way to extend the use of the BrowseDialogs.

Juan Carlos Pazos
Juan Carlos Pazos
StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)StrataFrame User (310 reputation)
Group: Forum Members
Posts: 144, Visits: 227
Que tal,

Sería factible que pusieras un ejemplo de tu proceso, la parte del View la puedo manejar pero el proceso de filtrar duplicados y demás no se me ocurre como hacerlo.

Gracias,

Smile Everything is possible, just keep trying...

Ivan George Borges
Ivan George Borges
Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Hola Juan.

Si, prepararé un ejemplo para usted y pondré aquí.

Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Ivan George Borges (10/31/2008)
Hola Juan.

Si, prepararé un ejemplo para usted y pondré aquí.

Aha, Ivan tu eres como una cajita de sorpresa, no sabia que hablabas y escribes en Español.Smile

Edhy Rijo

Ivan George Borges
Ivan George Borges
Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Hey Edhy.

I can read it, but not really write it. I asked for help over here... BigGrin

Ivan George Borges
Ivan George Borges
Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Hi Juan.

I read the code I posted to you and noticed I didn't code some important features in it, so I corrected a bit:

    Private Sub MyBrowseDialog1_BrowseDialogClosed(ByVal e As MicroFour.StrataFrame.UI.Windows.Forms.BrowseDialogClosedEventArgs) Handles MyBrowseDialog1.BrowseDialogClosed
        '-- check if the BrowseDialog was canceled by user
        If e.Reason = MicroFour.StrataFrame.UI.Windows.Forms.BrowseDialogClosedReasons.UserCancelled Then
            Exit Sub
        End If

        '-- establish locals
        Dim lnCount As Integer
        Dim lnChosenPk As Integer

        '-- get the chosen row PK
        lnChosenPk = Me.MyViewInfoBO1.myview_pk

        '-- copy the data from the populated BO to another one without the duplicates
        '-- (I used to do something a lot more complicate at this point, thanks to Paul for the next line)
        Me.MyViewInfoBO2.CopyDataFrom(Me.MyViewInfoBO1.CurrentDataTable.DefaultView.ToTable _
          (True, New String() {"myview_pk"}), _
           MicroFour.StrataFrame.Business.BusinessCloneDataType.ClearAndFillFromCompleteTable)

        '-- get the number of unique rows
        lnCount = Me.MyViewInfoBO2.Count()

        '-- establish an array dimensioned with the number of rows in the BO
        Dim arPk(lnCount) As Integer

        '-- populate the array of PKs, so we can use it to populate the form BO with the found records
        For Each row As MyViewInfoBO In MyViewInfoBO2.GetEnumerable()
            arPk(MyViewInfoBO2.CurrentRowIndex) = MyViewInfoBO2.myview_pk
        Next

        '-- fill the Parent BO given the array of PKs
        Me.MyParentBO1.FillByPrimaryKey(arPk)
        '-- position the chosen row
        Me.MyParentBO1.NavigateToPrimaryKey(lnChosenPk)
    End Sub


Ivan George Borges
Ivan George Borges
Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Here you are.
  • Get your view ready with the Parent and all its children, remember to have the parent PK as a column in it.
  • Create a new BO in your application and use the Business Object Mapper to map it. Remember that if you are used to mapping selecting the DDT as a source, with a view you will need to go straight to the SQL Server, so deploy it first, and then map it.
  • Rebuild your project and drop 2 instances of the view BO on your form.
  • Drop a BrowseDialog and configure it to this BO type, use one of the instances of the BO as the BusinessObjectToPopulate.
  • Configure your BrowseDialog as usual. SearchFields, BrowseResultsLayout and so on.
  • Go to your BrowseDialog Events and create one for BrowseDialogClosed.

In it, put some code like the following:

    Private Sub MyBrowseDialog1_BrowseDialogClosed(ByVal e As MicroFour.StrataFrame.UI.Windows.Forms.BrowseDialogClosedEventArgs) Handles MyBrowseDialog1.BrowseDialogClosed
        '-- establish locals
        Dim lnCount As Integer

        '-- copy the data from the populated BO to another one without the duplicates
        '-- (I used to do something a lot more complicate at this point, thanks to Paul for the next line)
        Me.MyViewInfoBO2.CopyDataFrom(Me.MyViewInfoBO1.CurrentDataTable.DefaultView.ToTable _
          (True, New String() {"myview_pk"}), _
           MicroFour.StrataFrame.Business.BusinessCloneDataType.ClearAndFillFromCompleteTable)

        '-- get the number of unique rows
        lnCount = Me.MyViewInfoBO2.Count()

        '-- establish an array dimensioned with the number of rows in the BO
        Dim arPk(lnCount) As Integer

        '-- populate the array of PKs, so we can use it to populate the form BO with the found records
        For Each row As MyViewInfoBO In MyViewInfoBO2.GetEnumerable()
            arPk(MyViewInfoBO2.CurrentRowIndex) = MyViewInfoBO2.myview_pk
        Next

        '-- fill the Parent BO given the array of PKs
        Me.MyParentBO.FillByPrimaryKey(arPk)
    End Sub

That should be it. Wink

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Russell Scott Brown - 17 Years Ago
Trent L. Taylor - 17 Years Ago
Aaron Young - 17 Years Ago
Ivan George Borges - 17 Years Ago
Juan Carlos Pazos - 17 Years Ago
                         Hola Juan. Si, prepararé un ejemplo para usted y pondré aquí.
Ivan George Borges - 17 Years Ago
                             [quote][b]Ivan George Borges (10/31/2008)[/b][hr]Hola Juan. Si,...
Edhy Rijo - 17 Years Ago
                                 Hey Edhy. I can read it, but not really write it. I asked for help...
Ivan George Borges - 17 Years Ago
                                     Hi Juan. I read the code I posted to you and noticed I didn't code...
Ivan George Borges - 17 Years Ago
                             Here you are. Get your view ready with the Parent and all its...
Ivan George Borges - 17 Years Ago
Russell Scott Brown - 17 Years Ago
Edhy Rijo - 17 Years Ago
                         I still have to use (but not for much longer :)) VPME andxCase2VPM and...
Aaron Young - 17 Years Ago
Russell Scott Brown - 17 Years Ago
Juan Carlos Pazos - 17 Years Ago
Ivan George Borges - 17 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search