代码之家  ›  专栏  ›  技术社区  ›  lancscoder

CSLA未报告对象在更改后变脏

  •  2
  • lancscoder  · 技术社区  · 16 年前

    我有一个CSLA对象正在从数据库返回数据,很好,但是当我更改对象的任何属性时,该对象仍然会说isdirty=“false”。尽管当我创建一个新对象时,它会报告isdirty=“true”。我确信这只是我在代码中缺少的一些简单的东西。以下是我的目标:

        [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;
            }
        }
    }
    

    任何帮助都将不胜感激。

    谢谢

    1 回复  |  直到 16 年前
        1
  •  6
  •   Ricky Supit    16 年前

    属性setter应使用setproperty而不是loadproperty

    前任:

    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
    }