5

If I am not concerned with unit testing and switching my data access out at a later time, would using my entity framework objects as my business objects be okay?

I have an existing database for which I generated entities and a datacontext, and have partial classes for holding my methods and any additional (non-database) properties. I have read quite a bit about repository pattern and other seemingly complex ways of setting this up, but I'm not sure all of that is necessary. It is a .NET Web Forms app using Entity Framework 6.1.3 and will not have unit testing.

Are there other reasons why I should avoid such a simplistic approach?

  • Typically, you don't pass data objects directly through a repository. Rather, you organize your repository actions around business processes. If your intention is to use Entity Framework as merely a data access mechanism, then you don't need repositories (a perfectly valid approach). That said, repositories are meant to be an organizing principle, not a means to add unwarranted complexity. – Robert Harvey Jul 20 '15 at 20:53
  • @RobertHarvey The intention is indeed just for simple data access.Thanks for your response. – user2023116 Jul 20 '15 at 21:18
2

I don't think you should use them as business objects. According to Vaughn Vernon EF is too inflexible be used directly as business objects

Instead use them as state objects. That is wrap them with a better encapsulation of your business logic. In the link I provided he i talking about DDD. What you refer to as business objects are called aggregate roots in DDD but the point still stands.

0

I would not extend POCOs to use them as business objects. It will mix domain logic with data logic and the codes become very difficult to maintain in the future.

But you also mentioned you will not have unit testing. So maybe you are building some one-off, short-lived project that does not need to be maintained and then it may be Okay. Just remember it may create lots of technical debts that you (or other devs) have to deal with later.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.