@Hoy Cheung , Welcome to Microsoft Q&A, please refer to the following steps to execute the stored procedure in ef for a keyless table.
First, I create a table and stored procedure like the following:
CREATE PROCEDURE [dbo].[GetAge]
@age int
AS
SELECT Name from Employee where Age>@age
RETURN 0
Second, Please add a new item called ADO.NET Entity Data Model to my project.
Second, Please click EF Designer from database and click Next.
Third, Please choose database and click Next.
Fourth, Please choose the table and the stored procedure and click finish.
Finally, we could see the generted code like the following:
public virtual ObjectResult<string> GetAge(Nullable<int> age)
{
var ageParameter = age.HasValue ?
new ObjectParameter("age", age) :
new ObjectParameter("age", typeof(int));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<string>("GetAge", ageParameter);
}
We could get the data by using the following code:
TestEntities context = new TestEntities();
var result=context.GetAge(26);
The result:(the username who's age is less than 26)
Hope the above solution could help you.
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.