之前整理了一下XPO在Session管理和缓存方面的一些资料(XPO:Session管理与缓存--机制篇),但原文的例程还是有些含糊的地方,这两天抽空做了一下测试。若有不当或者不对的地方敬请不吝赐教。
XPO初始化的代码就不重复贴了,这里只贴上主要的代码。
测试中构建了2个简单的类,XpoUser和XpoOrder,一对多的关系。
using System;
using DevExpress.Xpo;
namespace Model
{
public class XpoUser : XPObject
{
public XpoUser()
: base()
{
// This constructor is used when an object is loaded from a persistent storage.
// Do not place any code here.
}
public XpoUser(Session session)
: base(session)
{
// This constructor is used when an object is loaded from a persistent storage.
// Do not place any code here.
}
public override void AfterConstruction()
{
base.AfterConstruction();
// Place here your initialization code.
}
private string _Name;
public string Name
{
get
{
return _Name;
}
set
{
SetPropertyValue("Name", ref _Name, value);
}
}
[Association("XpoUser-Orders")]
public XPCollection<XpoOrder> Orders
{
get
{
return GetCollection<XpoOrder>("Orders");
}
}
}
}
using DevExpress.Xpo;
namespace Model
{
public class XpoUser : XPObject
{
public XpoUser()
: base()
{
// This constructor is used when an object is loaded from a persistent storage.
// Do not place any code here.
}
public XpoUser(Session session)
: base(session)
{
// This constructor is used when an object is loaded from a persistent storage.
// Do not place any code here.
}
public override void AfterConstruction()
{
base.AfterConstruction();
// Place here your initialization code.
}
private string _Name;
public string Name
{
get
{
return _Name;
}
set
{
SetPropertyValue("Name", ref _Name, value);
}
}
[Association("XpoUser-Orders")]
public XPCollection<XpoOrder> Orders
{
get
{
return GetCollection<XpoOrder>("Orders");
}
}
}
}