I have a stored procedure in SQL as below:
我在SQL中有一个存储过程,如下所示:
CREATE PROCEDURE USP_Select
(@id INT)
AS
SELECT * FROM EMO;
SELECT * FROM student WHERE id = @id;
SELECT * FROM tbl1;
RETURN 0
I am getting data using Entity Framework from that stored procedure using this code:
我使用以下代码从该存储过程使用Entity Framework获取数据:
Modalities context = new Modalities();
context.USP_Select(1);
How can I define which table data gets in my code?
如何定义代码中的表数据?
So here how can I get data different tables in code from the stored procedure?
那么在这里如何从存储过程中获取代码中的数据不同的表?
2 个解决方案
#1
0
first, add your stored procedure in .edmx file and create a complex type for that stored procedure and you can use an entity. Use the following link to create complex type
首先,在.edmx文件中添加存储过程并为该存储过程创建复杂类型,然后可以使用实体。使用以下链接创建复杂类型
Adding stored procedures complex types in Entity Framework
在Entity Framework中添加存储过程复杂类型
#2
0
Cant you just pass a parameter to select which table you wanna get data from?
你只是传递一个参数来选择你想从哪个表中获取数据?
CREATE PROCEDURE USP_Select
@table varchar(50),
@id INT = NULL
AS
BEGIN
IF @table = "EMO"
BEGIN
SELECT * FROM EMO;
END
ELSE IF @table = "student"
BEGIN
SELECT * FROM student WHERE id = @id;
END
ELSE IF @table = "tal1"
BEGIN
SELECT * FROM tbl1;
END
END
#1
0
first, add your stored procedure in .edmx file and create a complex type for that stored procedure and you can use an entity. Use the following link to create complex type
首先,在.edmx文件中添加存储过程并为该存储过程创建复杂类型,然后可以使用实体。使用以下链接创建复杂类型
Adding stored procedures complex types in Entity Framework
在Entity Framework中添加存储过程复杂类型
#2
0
Cant you just pass a parameter to select which table you wanna get data from?
你只是传递一个参数来选择你想从哪个表中获取数据?
CREATE PROCEDURE USP_Select
@table varchar(50),
@id INT = NULL
AS
BEGIN
IF @table = "EMO"
BEGIN
SELECT * FROM EMO;
END
ELSE IF @table = "student"
BEGIN
SELECT * FROM student WHERE id = @id;
END
ELSE IF @table = "tal1"
BEGIN
SELECT * FROM tbl1;
END
END