简体   繁体   中英

How to call stored procedures in Cosmos DB via Entity Framework Core?

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

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>());
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM