I try to abstract my specific domain problem to a banking account, assume the following situation:
- I have an Banking Login of a certain customer.
- Each Customer can have multiple banking accounts which belong to the same login.
- Each banking account can have thousands of transactions.
I designed the class structure as folows (simplified):
public class Login
{
private List<Account> _bankingAccounts;
....more fields, ctor, getters, setters...
}
public class Account
{
private List<Transaction> _transactions;
....more fields, ctor, getters, setters...
}
public class Transaction
{
String _comment;
....more fields, ctor, getters, setters...
}
Well, but If I have let’s say 20 Account and each has 10000 transaction and I load the entire model from the database there would be a large amount of memory, even I don’t know if the customers needs all these transactions.
I thought to build a more simplified model like this:
public class Login
{
private List<SimpleAccount> _bankingAccounts;
....more fields, ctor, getters, setters...
}
public class SimpleAccount
{
....more fields, ctor, getters, setters...
}
public class Account
{
private List<Transaction> _transactions;
....more fields, ctor, getters, setters...
}
public class Transaction
{
String _comment;
....more fields, ctor, getters, setters...
}
Then I would load a account model with simplified Account (which does not contain all the transaction) and only i the user requests to see the transaction of a specific account I will load this single entire Account object.
Would that way be ok? Is there a better approach?
From your question I found that your basic need is ORM because (if I am not wrong) you want to two things
domain model mapping
but
with lazzy loading
By lazy loading We mean that relational objects only load when we try to access them.Simply When you want to see a specific student data that you never want to load automatically all courses of a student(which could be a collection) unless to don’t want to see his/her courses(in case a student and courses has a relation).
So for your problem you should use ORM which will provide you both solutions 🙂
Here is the list of some ORM provided by .Net