IsSelfDirty and DataPortal_Update / Child_Update

IsSelfDirty and DataPortal_Update / Child_Update

Old forum URL: forums.lhotka.net/forums/t/6601.aspx


DivisibleByZero posted on Thursday, March 12, 2009

Would it be a wise idea to do something like this in my DataPortal_Update and Child_Update methods?

private void DataPortal_Update()  //Child_Update(Parent parent)
{
    if( IsSelfDirty )
    {
         // database code
     }
    FieldManager.UpdateChildren(this);
}

RockfordLhotka replied on Thursday, March 12, 2009

Yes - though you'll probably want to open your connection in all cases, so you can re-use the same connection in the child objects (using ConnectionManager or one of the other manager classes).

DivisibleByZero replied on Friday, March 13, 2009

If I have the following object hierarchy:

Root
   Child
       Grandchild

and in Child.Child_Update() I don't use the ConnectionManager would it close the connection?


Root.DataPortal_Update
{
    using( var ctx = ConnectionManager<SqlConnection>.GetManager(Database.Foo) )
    {
    }
    FieldManager.UpdateChildren(this);
}

Child.Child_Update(Root parent)
{
    if( IsSelfDirty )  // false in this case
    {
        using( var ctx = ConnectionManager<SqlConnection>.GetManager(Database.Foo) )
        {
        }
        FieldManager.UpdateChildren(this);
    }
}

Grandchild.Child_Update(Child parent)
{
    if( IsSelfDirty )  // true in this case
    {
        // is this a new connection since Child didn't open it?
        using( var ctx = ConnectionManager<SqlConnection>.GetManager(Database.Foo) )
        {
        }
    }
}

RockfordLhotka replied on Friday, March 13, 2009

Normally you'd call UpdateChildren() inside the using statement in the root object, so all the objects reuse the same connection. The reason for this is to avoid using the DTC (and its performance hit) when using TransactionScope transactions.

Or if you are using manual transactions, it is still a good idea, because you can set up the transaction on the connection in the root, and use that same connection (with its transaction) in the child objects.

As you show your code, it is virtually impossible to get any transactional protection - or if you do, it will involve the use of the DTC, so you'll take a perf hit.

jjloubser@symbioses.co.za replied on Wednesday, July 14, 2010

I am working in CSLA.net 4, Using a DataGrid with a BusinessListBase and  BusinessBase. My fetch work nice.

To update a line in the Grid my CanSave binding works on my apply button. I use this:

 <Button x:Name="ButtonApplyTop"
                            Width="75" Content="Apply"
                            IsEnabled="{Binding CanSave, Mode=OneWay}"/>

                    <my1:TriggerAction Height="0" x:Name="ButtonApplyTopTrigger" Width="0"
                               TargetControl="{Binding ElementName=ButtonApplyTop}"
                               TriggerEvent="Click" MethodName="Save"
                               />

 

When I click Apply it execute the save method, i know because i ovveride it, but do not reach my Child_Update() in the BusinessBase:

 private void Child_Update()
        {

        }

Do not even reach this in:

BusinessListBase:

 

 [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_Update()
        {
          
            using (var ctx = ConnectionManager<SqlConnection>.GetManager("StaffSenseDb"))
            {
                base.Child_Update(ctx);
                //FieldManager.UpdateChildren(this);
              
            }
        }

 

What is wrong? Please help.

jjloubser@symbioses.co.za replied on Wednesday, July 14, 2010

I also try this in the child object not working:

 

[Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_Update()
        {
            base.DataPortal_Update();

            using (var ctx = ConnectionManager<SqlConnection>.GetManager("xxxx"))
            {

            }

     }

JJLoubser replied on Wednesday, August 18, 2010

VMMV Search:

public void Search()
   {

       Presenter.ShowStatus(new Status { IsBusy = true, Text = "Searching row calls..." });
       BeginRefresh("Search");

 

}

 

Client Side:

 public static void Search(EventHandler<DataPortalResult<RowCallSummaryRORL>> callback)
        {
            var dp = new DataPortal<RowCallSummaryRORL>();
            dp.FetchCompleted += callback;
            dp.BeginFetch(rowCallSummaryDateCriteria_);
        }

Server side:

 

private void Child_Fetch(SafeDataReader dr, Business.RowCall.RowCallDetailsCriteria criteria)
        {

 

...

       }

 

Apply:

 

server side:

 private void Child_Update()
        {

...

       }

 

we just had to play around with the ViewModel verbs, Server Side names and Criteria Objects content

 

Copyright (c) Marimer LLC