Deferred load class
Public classLazyloader<tmodel>whereTModel:class{TModel _data; Func<TModel> _loaddatafunc =NULL; BOOL_loaded =false; PublicLazyloader (): This(NULL){ } PublicLazyloader (func<tmodel>Loaddatafunc) {_loaddatafunc=Loaddatafunc; _data=NULL; _loaded=false; } PublicTModel Querydata () {if(!_loaded && _loaddatafunc! =NULL) {_data=_loaddatafunc (); } return_data; } Public voidSetData (TModel value) {_data=value; _loaded=true; }}lazyloader
How to use (simply to name a column)
For example, the employee menu might not need to load his menu when you re-use the employee's object. When you want to use it, you need to delay loading it.
Public classEmployee { PublicLazyloader<ienumerable<menu>>_menus; PublicEmployee (Guid employeeId,stringEmployeeno,stringNamestringPasswordstringEmailstringPhoneBOOLEnabledBOOLIsadministrtor, DateTime Registerdate,stringRemarkstringiplimitation) {EmployeeId=employeeId; Employeeno=Employeeno; Name=name; Password=password; Email=email; Phone=phone; Enabled=enabled; Isadministrator=Isadministrtor; Registerdate=registerdate; Remark=remark; Iplimitation=iplimitation; _menus=NewLazyloader<ienumerable<menu>> (() =Systemresourceservice.querymenusbyemployeeid (employeeId)); } PublicGuid EmployeeId {Get;Private Set; } Public stringEmployeeno {Get;Private Set; } Public stringName {Get;Private Set; } Public stringPassword {Get;Private Set; } Public stringEmail {Get;Private Set; } Public stringPhone {Get;Private Set; } Public BOOLEnabled {Get;Set; } Public BOOLIsadministrator {Get;Private Set; } PublicDateTime Registerdate {Get;Private Set; } Public stringRemark {Get;Private Set; } Public stringiplimitation {Get;Set; } Public ObjectId {Get{returnEmployeeId;} }}employee
Custom Lazy Load Classes