Reputation: 6159
I am working on an asp.net application and I have the following scenario:
I have an edmx filw with my tables and I created my Poco entities from the "Add Code Generation Item", my question is simply where should i add my custom methods for example (checkIfEmailExists, AddUser, etc..) since if I added them in my poco entities when running the custom tool or updating my edmx file the entities are regenerated and I am losing all my methods?
Upvotes: 1
Views: 264
Reputation: 9296
You entities should be separate from some business logic or security. You should create a class, like Security, where you would implement those methods which rely upon your entities, but you should not add them directly to your entities.
Every class that you create should try to follow single responsibility principle. Even though your entities classes probably only contain public properties, you should first think whether AddUser or CheckIfEmailExists really belong to those classes. If they don't belong there, separated them into their own class. If you have a strong argument for putting those things into your entities, then put those methods into those entities.
Then again, what does AddUser do? If you have a class/table Users, and another class/table UserDetails, would you have AddUser as part of the former class/table or the latter?
Upvotes: 3
Reputation: 4489
Generated classes are partial - it contains one part of the class. You can create another file elsewhere, follow the naming (i.e. namespace and class name and the partial
keyword). This file won't be rewritten when new autogeneration is performed. You put your custom code here. The files are "merged" by compiler.
Upvotes: 2