Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 更改后CSLA未将对象报告为脏对象_Asp.net_Asp.net Mvc_Business Objects_Csla - Fatal编程技术网

Asp.net 更改后CSLA未将对象报告为脏对象

Asp.net 更改后CSLA未将对象报告为脏对象,asp.net,asp.net-mvc,business-objects,csla,Asp.net,Asp.net Mvc,Business Objects,Csla,我有一个从数据库返回数据的CSLA对象,但当我更改对象上的任何属性时,该对象仍然显示IsDirty=“false”。虽然当我创建一个新对象时,它会报告IsDirty=“true”。我确信这只是我的代码中缺少的一些简单的东西。以下是我的目标: [Serializable()] [ObjectFactory( FactoryNames.SiteFactoryName )] public class Site : BusinessBase<Site> { #region B

我有一个从数据库返回数据的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;
        }
    }
}
[Serializable()]
[ObjectFactory(FactoryName.SiteFactoryName)]
公共类网站:BusinessBase
{
#区域业务方法
公共静态属性info IdProperty=RegisterProperty(p=>p.Id);
公共整数Id
{
获取{return GetProperty(IdProperty);}
设置{LoadProperty(IdProperty,value);}
}
公共静态属性info-NameProperty=RegisterProperty(p=>p.Name);
公共字符串名
{
获取{return GetProperty(NameProperty);}
集合{LoadProperty(NameProperty,value);}
}
公共静态属性INFO CodeProperty=RegisterProperty(p=>p.Code);
公共字符串代码
{
获取{返回GetProperty(CodeProperty);}
集合{LoadProperty(CodeProperty,value);}
}
公共静态属性info-AliasProperty=RegisterProperty(p=>p.Alias);
公共字符串别名
{
获取{return GetProperty(别名属性);}
设置{LoadProperty(别名属性,值);}
}
公共静态属性info AddressProperty=RegisterProperty(p=>p.Address);
公共字符串地址
{
获取{返回GetProperty(AddressProperty);}
设置{LoadProperty(AddressProperty,value);}
}
公共静态属性info PostCodeProperty=RegisterProperty(p=>p.PostCode);
公共字符串邮政编码
{
获取{return GetProperty(PostCodeProperty);}
集合{LoadProperty(PostCodeProperty,value);}
}
公共静态属性Info InfoProperty=RegisterProperty(p=>p.Info);
公共字符串信息
{
获取{返回GetProperty(InfoProperty);}
设置{LoadProperty(InfoProperty,value);}
}
私有静态属性info CustomerLinkProperty=RegisterProperty(c=>c.CustomerLink);
公共int客户链接
{
获取{return GetProperty(CustomerLinkProperty);}
set{SetProperty(CustomerLinkProperty,value);}
}
私有静态属性info AccountsProperty=RegisterProperty(c=>c.Accounts);
政府帐目
{
get{return GetProperty(AccountsProperty);}
集合{SetProperty(AccountsProperty,value);}
}
#端区
#区域业务规则
受保护的覆盖无效AddBusinessRules()
{
}
#端区
#区域授权规则
受保护的覆盖无效AddAuthorizationRules()
{
//在此处添加授权规则
//授权规则。AllowWrite(名称属性,“项目经理”);
//授权规则。AllowWrite(StartedProperty,“项目经理”);
//授权规则。AllowWrite(EndedProperty,“项目经理”);
//AuthorizationRules.AllowWrite(DescriptionProperty,“ProjectManager”);
}
受保护的静态void AddObjectAuthorizationRules()
{
}
公共覆盖布尔CanWriteProperty(字符串属性名称)
{
返回true;
}
#端区
#区域传真法
公共静态站点NewSite()
{
返回DataPortal.Create();
}
公共静态站点GetSite(int-id)
{
返回DataPortal.Fetch(新的SingleCriteria(id));
}
公共静态站点GetSite(SiteCriteria SiteCriteria)
{
返回DataPortal.Fetch(siteCriteria);
}
公共静态void DeleteSite(int-id)
{
删除(新标准(id));
}
私人网站()
{/*需要使用工厂方法*/}
#端区
公共类站点标准
{
public int Id{get;private set;}
公共站点标准(int id)
{
Id=Id;
}
}
}
任何帮助都将不胜感激


谢谢

属性设置程序应该使用SetProperty而不是LoadProperty

例:

publicstaticpropertyinfo-NameProperty=RegisterProperty(p=>p.Name);
公共字符串名
{
获取{return GetProperty(NameProperty);}

set{SetProperty(NameProperty,value);}是否将该值更改为它加载的内容以外的内容?谢谢。这就是我复制和粘贴的结果!
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
}