寻找提高负载性能的建议。我有一个具有多个属性的复杂对象,最终会序列化为XML / JSON以进行数据传输。一些属性也是数据类型的集合(List<T>
),例如用户所属的“办公桌”。最终填充这些属性的数据存在于不同的数据库表等中。我目前实现了Lazy load来获取/设置这些属性。还有哪些其他设计和数据访问模式可以加快速度?
示例:
class MyDao
{
public int? uid { get; set; }
public string p1 {get;set;}
private Lazy<IEnumerable<string>> _desks;
public IEnumerable<string> desks
{
get { return _desk.Value; }
}
// More properties implemented via lazy...
public MyDao(int? id, string prop1)
{
uid = id;
p1 = prop1;
}
public void SetDesks(Func<int?,IEnumerable<string>> getDesk)
{
_desk = new Lazy<IEnumerable<string>>(() => getDesk(uid));
}
}
// Initialize
var dao = new MyDao(1,"something");
dao.SetDesk(MyDaoHelper.GetDesk);
// get desks
foreach(var desk in dao.desks){
//..do something with desk