问:如何为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
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/476.html