简体   繁体   English

如何根据Mysql EF6 C#中的存储过程生成复杂类型

[英]How to generate complex type according to stored procedure in Mysql EF6 C#

I'm trying to generate complex type by visual studio wizard, but when I try to call stored procedure where is required to pass parameters, wizard doesn't allow me to pass them. 我试图通过Visual Studio向导生成复杂类型,但是当我尝试在需要传递参数的地方调用存储过程时,向导不允许我传递它们。 在此输入图像描述

this is a my first problem, but it is not all, I changed my procedure, removed from them passing parameters to call directly and I'm getting following: 这是我的第一个问题,但这还不是全部,我更改了过程,从传递的参数中删除了传递参数以直接调用,然后得到以下结果:

在此输入图像描述

So it doesn't generate fields of complex type. 因此,它不会生成复杂类型的字段。 How can I solve this problem? 我怎么解决这个问题?

I can answer your first question. 我可以回答你的第一个问题。 I was facing the same in one of my recent projects. 在我最近的一个项目中,我也面临着同样的情况。 Here is how I solved it. 这是我如何解决它。

Create a view in MySQL containing the same column name and column type which you are returning from the stored procedure. 在MySQL中创建一个视图,其中包含与从存储过程返回的相同的列名和列类型。 Check my example below. 请在下面查看我的示例。

Stored procedure: spGetChartData 存储过程:spGetChartData

BEGIN
    SELECT A.ScAnSection, COALESCE(A.ScAnAnswer1, -1) AS ScAnAnswer1, A.ScAnBaselineFinal
    FROM schooolanswer A
    WHERE A.ScAnAcademicYear = 2018
    AND A.ScAnSchoolId = 10;
END

View: vwGetChartData 查看:vwGetChartData

select 'ScAnSection' AS `ScAnSection`,1 AS `ScAnAnswer1`,1 AS `ScAnBaselineFinal`

Now import both, your stored procedure and view in entity framework. 现在,同时导入您的存储过程和实体框架中的视图。 Then from Model Browser, edit your stored procedure and select "Entities" in "Returns a collection of" section. 然后从模型浏览器中,编辑您的存储过程,并在“返回一个集合”部分中选择“实体”。 From dropdown, select the view corresponding to your stored procedure. 从下拉列表中,选择与您的存储过程相对应的视图。

带有MySQL的EF中的存储过程

Hope this helps you solve the problem 希望这可以帮助您解决问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM