Entity Framework and Operations RRS feed

  • Question

  • Entity framework is very helpful by which you can generate all entities from the Database.

    For ex. I have Customer table from which I got my Customer class in Visual Studio solution. Now I want to add method called "GetCustomerByID" in the Customer class. Since EDMX models requires delete - regenerate when something changes in the database, how do I keep my operations which I wrote for my classes?

    I see the partial classes the simplest solution, but is there any better way or suggested practice where I want to utilize entity framework without loosing my own operations?


    Monday, April 30, 2012 9:54 PM


  • Hi,

    you don't have to delete the whole model or entity when you change something in de Database. The Designer can cope with these changes. The only thing he can't do automatically is when you delete or rename a field, but this can easily be done in the Designer.

    But back to your question. If the "GetCustomerByID" has to be in the entity your only and best shot is the partial class. And since this class is defined in an seperate file your changes are not lost as long as the entity and namespace stay the same.

    Another way would be am "managing" Class like an Factory, TableAdapter or a simple Manager Class. These seperate Objects would be the home of any Operation on the Customer vor example.


    Tuesday, May 8, 2012 8:10 AM