开发者

CSLA Not reporting object as dirty after being changed

开发者 https://www.devze.com 2022-12-20 01:02 出处:网络
I\'ve got a CSLA object that is returning data from the database fine but when I change any of the开发者_运维知识库 properties on the object the object still says IsDirty = \"false\". Although when I

I've got a CSLA object that is returning data from the database fine but when I change any of the开发者_运维知识库 properties on the object the object still says IsDirty = "false". Although when I create a new object it reports IsDirty = "true". I'm sure its just something simple that I'm missing in my code. The following is my object:

    [Serializable()]
[ObjectFactory( FactoryNames.SiteFactoryName )]
public class Site : BusinessBase<Site>
{
    #region Business Methods

    public static PropertyInfo<int> IdProperty = RegisterProperty<int>( p => p.Id );
    public int Id 
    {
        get { return GetProperty( IdProperty ); }
        set { LoadProperty( IdProperty, value ); }
    }

    public static PropertyInfo<string> NameProperty = RegisterProperty<string>( p => p.Name );
    public string Name
    {
        get { return GetProperty( NameProperty ); }
        set { LoadProperty( NameProperty, value ); }
    }

    public static PropertyInfo<string> CodeProperty = RegisterProperty<string>( p => p.Code );
    public string Code
    {
        get { return GetProperty( CodeProperty ); }
        set { LoadProperty( CodeProperty, value ); }
    }

    public static PropertyInfo<string> AliasProperty = RegisterProperty<string>( p => p.Alias );
    public string Alias
    {
        get { return GetProperty( AliasProperty ); }
        set { LoadProperty( AliasProperty, value ); }
    }

    public static PropertyInfo<string> AddressProperty = RegisterProperty<string>( p => p.Address );
    public string Address
    {
        get { return GetProperty( AddressProperty ); }
        set { LoadProperty( AddressProperty, value ); }
    }

    public static PropertyInfo<string> PostCodeProperty = RegisterProperty<string>( p => p.PostCode );
    public string PostCode
    {
        get { return GetProperty( PostCodeProperty ); }
        set { LoadProperty( PostCodeProperty, value ); }
    }

    public static PropertyInfo<string> InfoProperty = RegisterProperty<string>( p => p.Info );
    public string Info
    {
        get { return GetProperty( InfoProperty ); }
        set { LoadProperty( InfoProperty, value ); }
    }

    private static PropertyInfo<int> CustomerLinkProperty = RegisterProperty<int>( c => c.CustomerLink );
    public int CustomerLink
    {
        get { return GetProperty( CustomerLinkProperty ); }
        set { SetProperty( CustomerLinkProperty, value ); }
    }

    private static PropertyInfo<Accounts> AccountsProperty = RegisterProperty<Accounts>( c => c.Accounts );
    public Accounts Accounts
    {
        get { return GetProperty( AccountsProperty ); }
        set { SetProperty( AccountsProperty, value ); }
    }

    #endregion

    #region Business Rules

    protected override void AddBusinessRules()
    {
    }

    #endregion

    #region Authorization Rules

    protected override void AddAuthorizationRules()
    {
        // add AuthorizationRules here
        //AuthorizationRules.AllowWrite( NameProperty, "ProjectManager" );
        //AuthorizationRules.AllowWrite( StartedProperty, "ProjectManager" );
        //AuthorizationRules.AllowWrite( EndedProperty, "ProjectManager" );
        //AuthorizationRules.AllowWrite( DescriptionProperty, "ProjectManager" );
    }

    protected static void AddObjectAuthorizationRules()
    {
    }

    public override bool CanWriteProperty( string propertyName )
    {
        return true;
    }

    #endregion

    #region Facotry Methods

    public static Site NewSite()
    {
        return DataPortal.Create<Site>();
    }

    public static Site GetSite( int id )
    {
        return DataPortal.Fetch<Site>( new SingleCriteria<Site, int>( id ) );
    }

    public static Site GetSite( SiteCriteria siteCriteria )
    {
        return DataPortal.Fetch<Site>( siteCriteria );
    }

    public static void DeleteSite( int id )
    {
        DataPortal.Delete( new SingleCriteria<Site, int>( id ) );
    }

    private Site()
    { /* require use of factory methods */ }

    #endregion

    public class SiteCriteria
    {
        public int Id { get; private set; }

        public SiteCriteria( int id )
        {
            Id = id;
        }
    }
}

Any help would be much appreciated.

Thanks


The property setter should use SetProperty instead of LoadProperty

ex:

public static PropertyInfo<string> NameProperty = RegisterProperty<string>( p => p.Name );
public string Name
{
    get { return GetProperty( NameProperty ); }
    set { SetProperty( NameProperty, value ); } <--- use SetProperty instead of LoadProperty
}
0

精彩评论

暂无评论...
验证码 换一张
取 消