locked
Generic CRUD operation RRS feed

  • Question

  • User-1889312591 posted

    Hello,

    Is there any way or design pattern can I use to get Generic CRUD operation?

    Because   I’m working on n-tire application using EF in the data layer and I don’t want to use CRUD Functions in Every Entities.

    Your help would be appreciated

    Monday, April 12, 2010 12:45 PM

Answers

  • User653228039 posted

    I use repository pattern for Linq To Sql.  The Nerd Dinner tutorial I listed above actually discusses how to do it.  I haven't worked with the Entity Framework much, so I'm not sure how easy it is to port over, but I imagine the concepts are the same.  I like the repository pattern because you can swap out your underlying datamodel framework and the rest of your code can remain unchanged.  So if your code does something like this:


    UserAccount userAccount = userAccountRepository.GetUser(userId);


    and you decide your datamodel has to change significantly for whatever reason, all your business logic can stay the same if you just modify the "GetUser" function.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 13, 2010 7:41 PM

All replies

  • User653228039 posted

    Look into MVC for ASP.NET.  It has a lot of built-in features to create pages for each of the CRUD operations.


    Check out this tutorial to implement a semi-complex application using MVC:


    http://nerddinnerbook.s3.amazonaws.com/Intro.htm

    Monday, April 12, 2010 2:16 PM
  • User-1889312591 posted

    Thanks for your response, but I'm not using MVC I use the asp.net WebFrom.

    So Is there another solution??

    Monday, April 12, 2010 2:54 PM
  • User1491356988 posted

    Check out Linq to SQL or Entity Framework or any other ORM tool. 

    Monday, April 12, 2010 4:51 PM
  • User-1889312591 posted

    I heard about the Repository Pattern .Is that the right technical to use with EF to get the Generic operation in n-tire application?

    Monday, April 12, 2010 10:11 PM
  • User-1636183269 posted

    I will prefer to use Entity spaces. 

    Monday, April 12, 2010 10:23 PM
  • User-1889312591 posted

    Sorry,

    Can you give more details? 

    Monday, April 12, 2010 10:51 PM
  • User-1889312591 posted

    Thank you for you response

    but Is there any problem in Repository Pattern or Unit Of Work Pattern ????

    Monday, April 12, 2010 11:04 PM
  • User653228039 posted

    I use repository pattern for Linq To Sql.  The Nerd Dinner tutorial I listed above actually discusses how to do it.  I haven't worked with the Entity Framework much, so I'm not sure how easy it is to port over, but I imagine the concepts are the same.  I like the repository pattern because you can swap out your underlying datamodel framework and the rest of your code can remain unchanged.  So if your code does something like this:


    UserAccount userAccount = userAccountRepository.GetUser(userId);


    and you decide your datamodel has to change significantly for whatever reason, all your business logic can stay the same if you just modify the "GetUser" function.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 13, 2010 7:41 PM