CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

When use CustomField and ToUpperCase rule of cslacontrib, the BO's state IsDirty is incorrect.

rated by 0 users
Not Answered This post has 0 verified answers | 3 Replies | 0 Followers

Top 150 Contributor
57 Posts
simon posted on Tue, Apr 3 2012 6:43 AM

When the TextBox(binding MaterialNo and apply ToUpperCase rule) changed. the ViewModelBase's CanSave is still false.

If remove the below code in BussinessCore of CustomFiled, will run well.

 

     public override bool IsSelfDirty

        {

            get

            {

                if (IsDeleted) return true;

 

                var isSelfDirty = false;

                foreach (var registeredProperty in this.FieldManager.GetRegisteredProperties())

                {

                    if (registeredProperty.RelationshipType.HasFlag(RelationshipTypes.Child))

                    {

                        // skip lazy fields (is by definition child object)

                        if (!registeredProperty.RelationshipType.HasFlag(RelationshipTypes.LazyLoad))

                        {

                            var fieldData = FieldManager.GetFieldData(registeredProperty);

                            // fielddata object implements ITrackStatus it is a child object and must be excluded

 

                            if (!(fieldData is Csla.Core.ITrackStatus))

                            {

                                if (this.FieldManager.IsFieldDirty(registeredProperty))

                                {

                                    isSelfDirty = true;

                                    break;

                                }

                            }

                        }

                    }

                    else

                    {

                        if (this.FieldManager.IsFieldDirty(registeredProperty))

                        {

                            isSelfDirty = true;

                            break;

                        }

                    }

 

                }

                return isSelfDirty;

            }

        }

All Replies

Top 10 Contributor
1,813 Posts

1. That is the expected behvior when datasource updatemode is OnPropertyChanged. If you want to change the characters to uppercase as the user types then this must be handled in the UI code. 

2.  CustomFieldData ha its own implementation of IsDirty handling. You'll have to debug this code.

Jonny Bekkum, Norway CslaContrib Coordinator

Top 150 Contributor
57 Posts
simon replied on Wed, Apr 4 2012 12:14 AM

I found the reason.

the ToUpperCase will invoke the MarkClean  again.

public override void MarkClean()

{

base.MarkClean();

this.SetOriginalValue(this.Value);

}

this cause the OriginalValue be set again with the new value( convert by ToUpperCase).

but i don't find solution to avoid it.

Please help me. thank you.

Top 10 Contributor
1,813 Posts

Hi, 

In this case look for overrides of LoadProperty in your business objects (BusinessCore?).

CSLA rule engine will only call LoadProperty to update the value.

Jonny Bekkum, Norway CslaContrib Coordinator

Page 1 of 1 (4 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems