我不知道这是我的错误还是 Devexpres XPO 中的错误?(版本 12.1.5)
看一下以下示例:
static void Main(string[] args)
{
var dxs = Session.DefaultSession;
var sw = new Stopwatch();
using (var uow = dxs.BeginNestedUnitOfWork())
{
var dbp = new DBParent(uow) { TitleXX = "Morgan" };
// add 1000 child to the parent table
for (var i = 0; i < 1000; i++)
{
var dbc = new DBChild(uow)
{
Name = string.Format("Child {0}", i),
Parent = dbp
};
}
var count = uow.GetObjectsToSave();
// count = 1001
sw.Start();
uow.CommitChanges();
sw.Stop();
Console.WriteLine("Time:" +sw.Elapsed);
// Takes about 7 sec
}
using (var uow = dxs.BeginNestedUnitOfWork())
{
var dbp = new XPCollection<DBParent>(uow).First();
dbp.TitleXX = "Another title";
dbp.Save();
var count = uow.GetObjectsToSave();
// count = 1
sw.Reset();
sw.Start();
uow.CommitChanges();
sw.Stop();
Console.WriteLine("Time:" + sw.Elapsed); // Takes about 4 sec ????
}
Console.ReadLine();
}
}
这是我的对象:
public class DBParent : XPObject
{
public DBParent(){}
public DBParent(Session session) : base(session) { }
private string _TitleXX;
public string TitleXX
{
get { return _TitleXX; }
set { SetPropertyValue("TitleXX", ref _TitleXX, value); }
}
[Association("a1"), Aggregated]
public XPCollection<DBChild> Childs
{
get
{
return GetCollection<DBChild>("Childs");
}
}
}
public class DBChild : XPObject
{
public DBChild(){}
public DBChild(Session session): base(session){}
private string _Name;
public string Name
{
get { return _Name; }
set { SetPropertyValue("Name", ref _Name, value); }
}
private DBParent _Parent;
[Association("a1")]
public DBParent Parent
{
get { return _Parent; }
set { SetPropertyValue("Parent", ref _Parent, value); }
}
}
如您所见,保存 1001(1000 个子对象 + 1 个父对象)需要 7 秒,而在下一个块中更新 1 个父对象需要 4 秒。我已经针对 MS Access 和 MS SQL 2008 和 MSSQL-Compact 进行了测试,但结果都相同。任何建议表示赞赏。