Click here to Skip to main content
15,891,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

i have created the stored procedure which returns data from multiple tables.

Here i i am unable(don't know) to call the stored procedure with parameter.

Can anyone please help me to resolve this.

I tried with one scenario its returns

Id = 18, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}"


What I have tried:

created the console application.
1.created the models for all tables. stored procedures i cant.

2. Program.cs
-------------
var test = context.GetmessageAsync(int productId)


2. DBContext File
-----------------
public async Task<List<Getmessage>> GetmessageAsync(int productId)
{
	// Initialization.  
	List<Getmessage> lst = new List<Getmessage>();

	try
	{
		// Settings.  
		SqlParameter usernameParam = new SqlParameter("@id", productId.ToString() ?? (object)DBNull.Value);

		// Processing.  
		string sqlQuery = "EXEC [dbo].[Getmessage] " +
						  "@id";

		lst = await this.Query<Getmessage>().FromSql(sqlQuery, usernameParam).ToListAsync();
	}
	catch (Exception ex)
	{
		throw ex;
	}
}
Posted
Updated 20-Feb-19 4:04am
v2
Comments
Richard Deeming 20-Feb-19 10:20am    
Have you registered the Getmessage type as a query type[^]?
Harsh Jadaun 3-Oct-21 0:27am    
Hi,
In my case the following command shows error:
SqlParameter usernameParam = new SqlParameter("@id", productId.ToString() ?? (object)DBNull.Value);

I'm using .net core 3.1 for practice, please suggest a solution for this.

1 solution

 
Share this answer
 
Comments
Richard Deeming 20-Feb-19 10:16am    
Those seem to be related to Entity Framework, not Entity Framework Core. IIRC, EF Core has some significant differences around stored procedures.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900