I’m following the suggested architectural path put forward in “Programming Entity Framework Code First”.
There is a DataAccess layer and a Model layer which both form separate projects in VS.
The Model layer holds my classes for business objects. The DataAccess layer has a reference to the Model project so that it can create a context and DbSets for each of my business objects.
The issue is that some classes in the Model need to access the data layer to perform calculations, however I cannot reference the DataAccess layer in my Model project as it will create a circular reference. The DataAccess layer must reference the Model layer so that it can create the DbSets. Please also note the calculations are read only – only getters, which are not persisted to the database.
I’ve been searching for hours on this and have found useful information but I think I’m missing something simple? POCO classes are meant to be simple, but my classes represent things that have some very related but more complicated calculations.
As a simple concrete example I have a Transaction class and an AccountBalance class. The Transaction class needs to know the AccountBalance on specific dates for display purposes – such as percentage change (this is just a simple example):
public class Transaction
{
public DateTime Date { get; set; }
public string Description { get; set; }
... etc
public double PercentageChange
{
get
{
// return TransactionAmount / AccountBalance on TransactionDate
// however Transaction has no knowledge of AccountBalance...
}
}
}
Thanks