使用实体框架6中的工作单元和存储库模式调用存储过程。 [英] Call Stored Procedures using Unit Of Work and Repository Pattern in Entity Framework 6.

查看:88
本文介绍了使用实体框架6中的工作单元和存储库模式调用存储过程。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

向所有人致意



我正在使用工作单元,存储库模式与实体框架6(代码优先方法)以及依赖注入,



我已扩展我的存储库以执行以下存储过程



public List< tentity> ExecuteStoreProcedure(IUnitOfWork unitofWork,string spName,params object [] parameters)

{

return((DataContext)unitofWork.getDBContext())。Database.SqlQuery< tentity>( spName,parameters)。ToList();

}





我的问题是。

1.如何使用这种设计模式调用我的调用我的存储过程(我正在做的是正确的)。

2.如何让实体框架生成类来保存来自我的存储过程的数据(< tentity>)。

a)我有很多存储过程,我不想为所有这些创建POCO类。

Greetings to all

I am using unit of work, repository pattern with entity framework 6 (code first approach) along with dependency injection,

I have extended my repository to execute stored procedures as below

public List<tentity> ExecuteStoreProcedure(IUnitOfWork unitofWork, string spName, params object[] parameters)
{
return ((DataContext)unitofWork.getDBContext()).Database.SqlQuery<tentity>(spName, parameters).ToList();
}


my questions are.
1.How can I call my call my stored procedures using this design pattern(is what I am doing is correct).
2.How can I make entity framework generate classes to hold the data from my stored procedures on the fly(<tentity>).
a) I have lots of stored procedures and I do not want to create POCO classes for all of them.

推荐答案

你好Vailbhav Nigam。



如果你免费那么你可以查看以下链接



http://www.remondo.net/repository -pattern-example-csharp / [ ^ ]
Hi Vailbhav Nigam.

If u r Free then u can checkout the below link

http://www.remondo.net/repository-pattern-example-csharp/[^]


这篇关于使用实体框架6中的工作单元和存储库模式调用存储过程。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆