У меня есть модель/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));
}
Теперь я не доволен обоими. В одном подходе я делаю все в одном классе-помощнике, но в других я каждый раз вызываю разные таблицы для каждого пользователя. Очень ценю, если кто-то поможет мне лучше решить. Благодаря!
Полностью согласен вас вас. Я собираюсь сделать вид в базе данных. – KrishnaDhungana