gpt4 book ai didi

c# - 如何使用 Entity Framework 获取mysql存储过程结果集到C#

转载 作者:行者123 更新时间:2023-11-29 12:47:11 25 4
gpt4 key购买 nike

我正在尝试使用 Entity Framework 获取 mysql 存储过程结果集以列出。我正在尝试这段代码:

using (var db = new DistributorEntities())
{
var returnedData = db.EmployeeInfor();
}

但是returnedData值为0。

这是我的mysql存储过程

CREATE DEFINER=`root`@`localhost` PROCEDURE `EmployeeInfor`()
BEGIN

DECLARE Type1 VARCHAR(30) DEFAULT '';
DECLARE Type2 VARCHAR(30) DEFAULT '';

CREATE TEMPORARY TABLE emp
SELECT
E.`Employee Code`, E.`First Name`,
E.`Middle Name`, E.`Last Name`,
E.Address, E.`Date of Birth`,
E.`NIC No`, E.`Employee Type 1`,
E.`Employee Type 2`, Type1,
Type2, E.`E mail`
FROM employee AS E
where E.isactive = 1;

CREATE TEMPORARY TABLE empType
SELECT `Employee Type Code`, `Type Description` FROM `employee type`;

SET SQL_SAFE_UPDATES = 0;

UPDATE emp AS E
INNER JOIN empType AS ET
ON E.`Employee Type 1` = ET.`Employee Type Code`
SET E.Type1 = ET.`Type Description`;

UPDATE emp AS E
INNER JOIN empType AS ET
ON E.`Employee Type 2` = ET.`Employee Type Code`
SET E.Type2 = ET.`Type Description`;

select
E.`Employee Code`,E.`First Name`,
E.`Middle Name`,E.`Last Name`,
E.Address,E.`Date of Birth`,
E.`NIC No`,E.Type1,
E.Type2,E.`E mail`
FROM emp AS E;

drop TABLE if exists empType;
drop TABLE if exists emp;

END

如何从表中检索数据?谢谢。

最佳答案

您也可以调用如下所示的存储过程,其中 {class name} 将是您的模型类,其中将包含从 sp 返回的所有属性。

var obj = (IObjectContextAdapter)this).ObjectContext.ExecuteStoreQuery<employee>("call EmployeeInfor").ToList();

关于c# - 如何使用 Entity Framework 获取mysql存储过程结果集到C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25278475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com