【发布时间】:2013-12-04 10:21:41
【问题描述】:
我有一个模型/POCO,它具有收入、资产比率、回报率等属性,这些属性是用户的绩效管理指标。这些属性中的每一个都是根据公式计算的。其中大多数需要查询不同的表来填充数据进行计算。目前我有两种方法:
public class Performance
{
public decimal Revenue {get; set;}
public decimal AssetRatio {get; set;}
// And so on
}
case 1
public class Helper
{
public List<Performance> GetPerformance()
{
var context = new SomeDbContext();
var revenue = context.Where(). some operation
var assetRatio = context.Where().. so on
//Each will have collection of user and performance indicator type.
//Eg: revenue is a list of users and revenue
//Now I Join all tables based on userId and create List<Performance>
//And return List<Performance>
}
}
I find this approach tedious and I tried another approach
case 2
public class Performance
{
private SomeDbContext _ctx = new SomeDataContext();
public SomeDbContext(int userId)
{
this.UserId = userId;
}
public int UserId {get; set;}
public decimal Revenue {get; set;}
public decimal AssetRatio {get; set;}
// And so on
// I have Private Methods that is dedicated to populate each associated property
private decimal getRevenue()
{
decimal revenue = ctx. ../ and so on
}
}
//This class is passed list of user id as list<int>
foreach (var user in UserList)
{
someList.Add(new Performance(user));
}
现在我对两者都不满意。在一种方法中,我在一个助手类中做所有事情,但在另一种方法中,我每次为每个用户调用不同的表。如果有人能指导我一个更好的解决方案,我真的很感激。谢谢!
【问题讨论】:
标签: asp.net-mvc oop poco