Firstly, with views of 11k questions at the time of writing this article, I am a little surprised at the lack of answers and with all due respect, the quality of the answers, given the rather simple question.
So, now that I have strayed a little, I would like to address this issue (s) because I think that today it also applies to the recent Entity Framework Code-First.
"Using Entity Framework Entities as Business Objects?"
A few clarification points before I started:
When you say “business objects”, I get the impression that the objects you refer to contain rules or logic, from, for example, simple validation (i.e. required fields) to more complex logic (i.e. e. processing tax on statement).
I do not think that I can answer your next question regarding WCF. The reason for this is that I am going to objectively answer your questions about EF as business objects, which would then subjectively force me to take a position that proves the inconsistency of my attempt to sincerely and objectively answer the first question.
/ li>
However, to your EF as a matter of business objects ...
"I use Microsoft's Entity Framework O / R object mapping module and using the class object (generated classes that are mapped to database objects) as business objects. Is this normal?"
Sorry, there is no right or wrong answer. It depends on your goal and what you consider the most reasonable project, at the same time fully understanding the advantages and disadvantages of this.
"Please indicate your minuses or pluses"
I'm glad you asked! I will be happy to answer, and I hope that, given the pros and cons, you can make an informed decision as to whether you think that using EF for your business objects is OK. As a rule, Id breaks the pros and cons, making it easy to “digest”, but I don’t think it is appropriate here because I think that we are injustice in relation to such a very interesting topic, which is also close and close to my heart.
First of all, let me speak technically for a moment ... You can use EF objects as your business objects, and nothing technically prevents you from doing this. Essentially, EF Code-First (CF) makes this incredibly simple, allowing you to create POCOs and give you the ability to apply data annotations for simple validation, as well as for implementing IValidatableObject for more complex validation. Pretty cool, huh?
This is the essence of the discussion.
EF, or any ORM, is designed to support data management. His main responsibility is data, and therefore the objects you create are data-oriented. So, if you try to also design your objects by behavior, you will have a little puzzle. In a nutshell, this puzzle is called impedance mismatch. Imagine it; You have two required use cases in your application:
- User Editing Screen
- A read-only display control of a subset of user information
If you use EF (any taste) or any ORM for that matter, you may be inclined to use the same User object to handle the ability to save the user, as well as to extract the user for a subset, only the field. Perhaps you are doing this for one of several reasons:
- Like many developers, we have this seed planted in our brains during training. "Strengthening the code" is of paramount importance or perhaps better known as DRY - Dont Repeat Yourself, and therefore you can look at code duplication, for example, in a negative context.
- ORMs such as EF 4.1 have technical limitations (and hacking workarounds), such as mapping multiple POCOs / objects to the same database table, thereby forcing you regardless of your beliefs.
- This is a quick and easy way to launch and run the application.
- It "feels" like the right thing.
There are advantages and disadvantages to this, and you can look at it either positively or negatively, depending on your opinion.
I suppose if you believe in normalizing your code compared to what you did significantly. You were able to limit the amount of code, potentially saving time by writing a single object for processing your data and business use cases for this object.
And I suppose, if you believe in normalizing behavior over code, than you failed. By saving the code, you sacrificed the design of objects with your responsibilities, which potentially complicated management and subsequently increased maintenance costs.
Regardless of your opinion, we can probably agree that this business object has taken on many responsibilities, and the behavior (and not data!) Of the object is secondary at best. His main responsibility is data management, and his secondary responsibilities are the processing of business rules, simple and complex, related to editing the user and displaying user information for read-only purposes. In object-oriented design (OOD), if the design of an object is characterized by its identity and behavior, this object can be one confused person, since it does not correspond to the very definition of OOD.
Something to keep in mind from a technical point of view, every time you request a user object, you inherit a significant portion of the overhead. This can include things like all properties and business rules when only a subset of read-only information is displayed.
So, what does all this have to do with whether I should use EF to represent my business objects?
Well ... Although it is technically possible, there are different philosophies (some good, some bad) about whether to use EF or any ORM to represent your business objects. I gave a review aimed at the heart of these philosophies above, but they are described in much more detail by people like Rocky Lhotka and Martin Fowler.
The direction you directed, most likely, will depend on the application and on the philosophical view, it may depend on how idealistic or pragmatic you are. However, I do not mean that one of the idealists or pragmatists correlates either with the use of EF for business objects or not - it will simply affect your approach to this.
At the time of this writing, Microsoft indicated that EFs are built to handle business logic and, right or wrong, they seem to be moving more in that direction. EF is constantly evolving, and some technical restrictions are removed so that EF can ultimately be used to satisfy the best of both worlds. In other words, you can eventually get your cake and eat it too.
Hope this helps.
Disable to answer the question of whether the lack of knowledge of persistence with ORM is ridiculous given the purpose behind it - to manage the data. :-) Sorry, I could not resist!