I am looking for a good example projects for using repository pattern and stored procedure. I have spent a lot of times,I can’t find any good example that use sp to commmunicate with repository pattern and db. Even a regular CRUD, I will still use SP.
Also, does anyone have an example to do complex data in stored procedure to code in EF?
For example, stored procedure return multiple data tables?
Thanks
Just think about the pattern and your options – you can use only SPs and you want object responsible for data access. You don’t need any example project – you just need to think.
When implementing repository with stored procedures you will end with simple DAO (data access object) defined by interface like:
This is basic interface for CRUD operations on
Entitypersisted class. Every method implementation will call single stored procedure to perform the operation. If you will need any other operation (for example some filtering or ordering) you will create new stored procedure and expose new operation calling this stored procedure.There can be discussion if this is or is not repository but simply SPs will not offer you anything more. For example this part of definition is mostly impossible to achieve on generic level:
Your “query specification” will always be only parameters specific to given stored procedure and passed to your exposed operation. You will not be able to declaratively define whole query (unless you pass SQL as parameter to your SP).
You can call stored procedures directly by ADO.NET or use either function imports or
ExecuteStoreQuery/ExecuteStoreCommandin EF. EF is able to execute complex stored procedures with this limitations:Function imports have few more minor limitations. If you follow these rules you will be able to create classes / complex types for every result set returned by your SP.