system developer in training here...
I'm in the middle of a .net core project, where we've tried to make a "nice architecture".
Currently, we have these projects: Models, DAL, BLL, UI (references kinda in that order too).
However, we've just decided to switch from entity framework to dapper, hence we'll loose lazy loading, and other features from ef.
My solution, in the models class, remove the references in the "base" models project, and have "derived" classes in the BLL.
However, when I was then working with the BL Layer repositories, I'm finding myself needing to cast from the base models class, to the derived extended models, giving me an InvalidCastException
.
Where did I go wrong? What would be the "proper" way to have done this from the beginning?
Example
In my models project, I'll have the class foo
and in BLL, a class: class foo : Models.foo
, then in the BLL repository class fooRepository
a method like:
public foo GetFooById(int Id) {
return (foo)DAL.FooRepository.GetById(Id)
}
- the foo here would be form the models extension in BLL, but the one comming from the DAL, would be
foo
's base class.
Specific, compilable example: https://github.com/jona8690/ChildInheritanceExample