tailieunhanh - Apress Expert C sharp 2005 (Phần 10)
Tham khảo tài liệu 'apress expert c sharp 2005 (phần 10)', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 2 26 06 10 02 PM Page 424 424 CHAPTER 8 BUSINESS OBJECT IMPLEMENTATION Notice how the code directly alters the instance fields of the object. For instance the _id field is set to a new Guid value. Since the Id property is read-only this is the only way to load the Id property with a new value. While the Started property is read-write and could be set through the property it is more efficient and consistent to directly set the _started field. Since not all properties can be set it is best to be consistent and always set fields directly. Additionally the call will apply all the validation rules in the entire object. Setting a property causes the validation rules for that property to be checked so setting property values would cause validation rules to be run twice which is wasteful. Setting the fields and then calling CheckRules means validation rules are run only once. Of course the default values set in a new object might not conform to the object s validation rules. In fact the Name property starts out as an empty string value which means it is invalid since that is a required property. Remember that this was specified in the AddBusinessRules method by associating this property with the StringRequired rule method. To ensure that all validation rules are run against the newly created object s data is called. Calling this method with no parameters causes it to run all the validation rules associated with all properties of the object as defined in the object s AddBusinessRules method. The end result is that the new object has been loaded with default values and those values have been validated. The new object is then returned by the data portal to the factory method NewProject in this case which typically returns it to the UI code. DataPortal_Fetch More interesting and complexis the DataPortal_Fetch method which is called by the data portal to tell the object that it should load its data from .
đang nạp các trang xem trước