I am using Cosmos DB in a project via Entity Framework Core. I want to run stored procedures through Entity Framework Core. I found a way how to do this through the Cosmos DB client, but I just can't find how to do it through Entity Framework Core
CodePudding user response:
You can call it from the System.Data.Entity.DbContext class and you can use it like this in c#:
var userTypes= ((IObjectContextAdapter) this). ObjectContext.ExecuteFunction<Nullable>("sp_procname", parameter1, parameter2);
You can check details here
CodePudding user response:
You have to import using Microsoft.EntityFrameworkCore
and then:
public async Task RunStoreProcedureAsync()
{
_context.Database.GetCosmosClient().GetContainer("databaseId", "containerId").Scripts
.ExecuteStoredProcedureAsync<string>("procedureId", new PartitionKey("yourKey"), Array.Empty<dynamic>());
}