使用实体框架动态调用存储过程

使用实体框架动态调用存储过程

本文介绍了使用实体框架动态调用存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我需要能够使用Entity Framework 4在C#中运行存储过程,并连接到Oracle 11 db.

我可以在编译时知道SP的情况下执行此操作,但是通常情况并非如此,因为不同的客户端具有不同的存储过程.

问题是这样的:我的程序是否可以在运行时确定要运行的存储过程并从中返回记录集?

例如:
客户端1具有存储过程A和B.
客户端2具有存储过程A,C和D.
客户端3具有存储过程E和F.

目前,我需要一个单独的映射和新代码来满足所有三个客户端,如果出现第四个客户端,则还需要另一个变体.

有什么方法可以在运行时而不是在编译时确定并执行它们吗?

在此先感谢

Paresh

Hi All.

I have a requirement to be able to run a stored procedure in C# with Entity Framework 4, connecting to an Oracle 11 db.

I can do this when the SP is known at compile time, but often this is not the case as different clients have different stored procedures.

The question is this: Is it possible for my program to determine at runtime which stored procedures to run and to return recordsets from them?

For example:
Client 1 has the Stored Procedures A & B.
Client 2 has the Stored Procedures A, C & D.
Client 3 has the Stored Procedures E & F.

At the moment I would need a separate mapping and new code to satisfy all three clients, and if a fourth came along that would need yet another variant.

Is there any way of determining and executing these at runtime rather than compile time?

Thanks in advance

Paresh

推荐答案

DataContext.Context.ExecuteStoreQuery<ilist><roles>>("seleci id from...",param object[] params);</roles></ilist>


<ilist><roles>></roles></ilist>表示返回值是Roles(我的数据库中的表)实体的列表,在输入方法中,您将查询脚本设置为脚本,并至少将params作为object[]添加到此方法! >抱歉,这不是您想要的解决方案,但是也许可以为您提供一些帮助!


<ilist><roles>></roles></ilist> means that the return value is a list of Roles(a table in my database) entity, in entry method you set the query script as a script, and at least add params as object[] to this method!
sorry this is not the solution that you want, but maybe this can help you a little!



这篇关于使用实体框架动态调用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 14:52