code_junkie

Business Entity Loading Pattern

Nov 11th, 2011
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. public class Relation<T>
  2. {
  3. private T _value;
  4.  
  5. private void FetchData()
  6. {
  7. if( LoadData != null ) {
  8. LoadDataEventArgs args = new LoadDataEventArgs(typeof(T), /* magic to get correct object */);
  9. LoadData(this, args);
  10. _value = (T)args.Value;
  11. }
  12. }
  13.  
  14. public event EventHandler<LoadDataEventArgs> LoadData;
  15.  
  16. public T Value {
  17. get {
  18. if( _value == default(T) )
  19. FetchData();
  20. return _value;
  21. }
  22. set { /* Do magic here. */ }
  23. }
  24. }
  25.  
  26. [RelationCriteria("ID", EqualsMyProperty="AddressID")]
  27. public Relation<Address> Address {
  28. get; set;
  29. }
Add Comment
Please, Sign In to add comment