gpt4 book ai didi

asp.net - CSLA 在更改后未将对象报告为脏对象

转载 作者:行者123 更新时间:2023-12-02 16:07:11 26 4
gpt4 key购买 nike

我有一个 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;
}
}
}

任何帮助将不胜感激。

谢谢

最佳答案

属性 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
}

关于asp.net - CSLA 在更改后未将对象报告为脏对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2267241/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com