1

I have a stored procedure in SQL as below:

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:

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?

6
  • Does this help? msdn.microsoft.com/en-us/library/jj691402(v=vs.113).aspx Commented Nov 2, 2017 at 11:20
  • Also, is it your context code first? Commented Nov 2, 2017 at 11:25
  • no it is not help. it is database first approach. Commented Nov 2, 2017 at 11:31
  • May be you can find a clue from this link : Link Commented Nov 2, 2017 at 11:32
  • @HumayounKabir it is not help Commented Nov 2, 2017 at 11:37

2 Answers 2

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

Adding stored procedures complex types in Entity Framework

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.