How to create a Generic Repository

LeandroHPA

Hi Folks!
First of all, thanks for all of you that are here reading. If you are not to help me, you are in the need of, so my post might help you ;)
If you are the one that knows how to make that. please, help me out!

I am migrating to Telerik ORM, and I am facing problem on implementing my Generic Repository that I have for Entity Framework.
Please find below my implementation of the IRepository class.

Please bear in mind that the update method is missing because the updates are automatically tracked by the context and you just need to call the SaveChanges method to commit the changes in the database.

In order to have the possibility to pass the same context instance to all of your repositories I replaced the inline initialization of its context with an injection in the constructor which will reduce your database calls - the queries will be executed in the same transaction when you call the SaveChanges method.

Regarding the best generic repository implementation - it is depending on your scenario. For example if you are making some serialization and deserialization of your entities I suggest you to take a look at our Web API service generated by the Add OpenAccess Service wizard where you are getting a repository with attaching and detaching of its entities implemented out of the box.

You could find useful examples of different generic repositories in the end-to-end sample applications of our Samples Kit - for Web API service examples you could take a look at the ASP.NET Web API with Kendo UI and ASP.NET Web API with WPF MVVM examples in the ASP.NET Web API section.

I hope this is applicable for you. Do not hesitate to contact us back if you need any further assistance.

If you choose using the Visual Studio functionality you could achieve that by right clicking on your class and selecting the Extract Interface operationfrom the Refactoring menu or using its CTRL+R, I shortcut.

I hope this helps. Do not hesitate to contact us back if you need any further assistance.

LeandroHPA

Hi Dimitar!
Thanks a bunch man! It sorted out my problems on this concern.

I am glad to being discovering and pactising with Kendo and also to have support from Telerik team. That means to me this company it's not only great on doing innovation, but beyond that, supporting us to come along, and keep it going and growing constantly.
P.S. I am a very potential future chargable member, but yet using for availing and learning purpose, and still got support on my problems.

Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.