我开始使用Silverlight/Flex,很快遇到了异步服务调用的问题。我已经习惯了用一种服务器提取机制或另一种服务器提取机制以面向对象的方式解决数据访问问题。
我有下面这个简单的代码示例:
public double ComputeOrderTotal(Order order)
{
double total = 0;
// OrderLines are lazy loaded
foreach (Orderline line in order.Orderlines)
{
// Article,customer are lazy loaded
total = total + line.Article.Price - order.Customer.discount;
}
return total;
}
如果我理解正确,这段代码在Flex / Silverlight中是不可能的。懒加载强制你使用回调函数。在我看来,上面的简单示例会非常混乱。
有人可以给我一个有结构的方式来实施上述内容吗?
编辑:
- The problem is the same for Flex/Silverlight, pseudo code would do fine
- Its not really ORM related but most orms use lazy loading so i ll remove that tag
- The problem is lazy loading in the model
- The above example would be very doable of all data was in memory but we assume some has to be fetched from the server
- Closueres dont help since sometimes data is already loaded and no asynchronous fetch is needed