DevExpress v21.2新版发布会·诚邀参与

DevExpress控件使用交流,DevExpress中国社区Dev联系电话 联系电话:023-68661681

如何为eXpressApp Framework设置默认属性值

来源:本站原创   发布时间:2013-04-10   浏览:2774次

问:如何为eXpressApp Framework设置默认属性值?

答:参考以下代码:

所有的base persistent classes都放在PersistentBase类中,这个类让用于初始化AfterConstruction method,

简单的属性值初始化:


public class Contact : Person {
//... 
    public override void AfterConstruction() {
        base.AfterConstruction();

        FirstName = "Sam";
        TitleOfCourtesy = TitleOfCourtesy.Mr;
    }
}


用当前或新的对象初始化Reference属性:


public class Contact : Person {
//... 
    public override void AfterConstruction() {
        base.AfterConstruction();

        Address1 = new Address(Session);
        Address1.Country = Session.FindObject<Country>(CriteriaOperator.Parse("Name = 'USA'"));
        if(Address1.Country == null) {
            Address1.Country = new Country(Session);
            Address1.Country.Name = "USA";                
            Address1.Country.Save();

        Manager = Session.FindObject<Contact>(CriteriaOperator.Parse(
            "FirstName = 'John' && LastName = 'Doe'"));
        }            
    }
}


Collection属性

用预定义的Phone numbers填充Phones collection:

public class Contact : Person {
//... 
    public override void AfterConstruction() {
        base.AfterConstruction();

        PhoneNumber phone1 = Session.FindObject<PhoneNumber>(CriteriaOperator.Parse(
            "Number = '555-0101'"));
        PhoneNumber phone2 = Session.FindObject<PhoneNumber>(CriteriaOperator.Parse(
            "Number = '555-0102'"));
        PhoneNumbers.Add(phone1);
        PhoneNumbers.Add(phone2);
    }
}

本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/476.html

联系我们
  • 重庆总部 023-68661681 400-700-1020
购买
  • sales@evget.com
合作
  • business@evget.com


在线
客服
在线
QQ
电话
咨询
023-68661681
返回
顶部