我有一个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;
}
}
}
非常感谢任何帮助。
由于
答案 0 :(得分:6)
属性设置器应该使用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
}