简体   繁体   中英

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. 在此输入图像描述

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. Check my example below.

Stored procedure: 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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