I am wondering sometimes how should I be making my repo methods.
I have this
public List<TableA> Get(Guid id)
{
return session.Query<TableA>().Where(x => x.Id== id).ToList();
}
Now I use this in a couple places in my service layers but in one place I need to do a select.
Should I do this
public List<string> GetNames(Guid id)
{
return session.Query<TableA>().Where(x => x.Id== id).Select(x => x.Name).ToList();
}
OR
//this is in my service layer
public void ServiceGet(Guid id)
{
myRepo.Get(id).Select(x => x.Name).ToList();
}
I am never sure if I should be making a new method or just return some general results and then let the service layer deal with filtering it down.
You should let your database do as much filtering as possible because that’s what it’s good at. When it comes time to do performance tweaking, this will give you the most flexibility. The tricky part is drawing the fine line between filtering and business logic.