.NET 學習

.NET 學習生活感想... 万事成蹉跎..... 贵在坚持 及时整理自己做过和学过的东西

博客园 首页 新随笔 联系 订阅 管理

http://community.devexpress.com/forums/p/60725/205569.aspx

http://www1.devexpress.com/Support/Center/p/B39252.aspx

代码:

 

[DefaultClassOptions]
    
public class Master : XPCustomObject
    {
        
public Master(Session session)
            : 
base(session)
        {
            
// This constructor is used when an object is loaded from a persistent storage.
            
// Do not place any code here or place it only when the IsLoading property is false:
            
// if (!IsLoading){
            
//    It is now OK to place your initialization code here.
            
// }
            
// or as an alternative, move your initialization code into the AfterConstruction method.
        }
        
public override void AfterConstruction()
        {
            
base.AfterConstruction();
            
// Place here your initialization code.
        }

        
private string _MasterName;
        
public string MasterName
        {
            
get
            {
                
return _MasterName;
            }
            
set
            {
                SetPropertyValue(
"MasterName"ref _MasterName, value);
            }
        }

        [Association(
"Master-Details")]
        
public XPCollection<Detail> Details
        {
            
get
            {
                
return GetCollection<Detail>("Details");
            }
        }

        
private MasterPrimaryKey _Key;
        [Key,Persistent,Browsable(
false)]
        
public MasterPrimaryKey Key
        {
            
get
            {
                
return _Key;
            }
            
set
            {
                SetPropertyValue(
"Key"ref _Key, value);
            }
        }

        [NonPersistent]
        
public string Key1
        {
            
get { return Key.Key1; }
            
set
            {
                _Key.Key1 
= value;
            }
        }
        [NonPersistent]
        
public string Key2
        {
            
get { return Key.Key2; }
            
set
            {
                _Key.Key2 
= value;
            }
        }
        
    }

    
public struct MasterPrimaryKey
    {
        [Persistent]
        
public string Key1;
        [Persistent]
        
public string Key2;
    }

  
public class Detail : XPCustomObject
    {
        
public Detail(Session session)
            : 
base(session)
        {
            
// This constructor is used when an object is loaded from a persistent storage.
            
// Do not place any code here or place it only when the IsLoading property is false:
            
// if (!IsLoading){
            
//    It is now OK to place your initialization code here.
            
// }
            
// or as an alternative, move your initialization code into the AfterConstruction method.
        }
        
public override void AfterConstruction()
        {
            
base.AfterConstruction();
            
// Place here your initialization code.
        }

        
private int _ID;
        [Key(AutoGenerate 
= true)]
        
public int ID
        {
            
get
            {
                
return _ID;
            }
            
set
            {
                SetPropertyValue(
"ID"ref _ID, value);
            }
        }

        
private string _DetailName;
        
public string DetailName
        {
            
get
            {
                
return _DetailName;
            }
            
set
            {
                SetPropertyValue(
"DetailName"ref _DetailName, value);
            }
        }

        
private Master _Master;
        [Association(
"Master-Details")]
        
public Master Master
        {
            
get
            {
                
return _Master;
            }
            
set
            {
                SetPropertyValue(
"Master"ref _Master, value);
            }
        }
    }

 欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/

 

posted on 2010-12-21 15:33  Tonyyang  阅读(833)  评论(0编辑  收藏  举报
欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/