Open Closed

How to use custom functions and stored procedure in microservices application #728


User avatar
0
lalitChougule created
  • ABP Framework version: v3.0.4
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Seperated (Angular): no / yes
  • Exception message and stack trace:
  • Steps to reproduce the issue:

I am using PostgreSQL functions and stored procedure.

I tried using it this approach https://khalidabuhakmeh.com/add-custom-database-functions-for-entity-framework-core

but I got below error: [ERR] xyzFunctionName cannot be called client side

Tried to look into abp document but no luck.

Please provide sample code if available. Thank you in advance !!!


3 Answer(s)
  • User Avatar
    0
    alper created
    Support Team Director

    There's a sample project show how to run Stored Procedures in ABP Framework.

    • https://docs.abp.io/en/abp/latest/Entity-Framework-Core#add-custom-repositories
    • https://github.com/abpframework/abp-samples/tree/master/StoredProcedureDemo
  • User Avatar
    0
    lalitChougule created

    Hi @alper,

    Below code is for Executing SP on SQL server:

    public async Task UpdateEmail(Guid id, string email, CancellationToken cancellationToken = default)
    {
        await DbContext.Database.ExecuteSqlRawAsync(
            "EXEC UpdateEmailById @email, @id",
            new List<object> {new SqlParameter("id", id), new SqlParameter("email", email)},
            cancellationToken);
    }
    

    I am using PostgreSQL 13 , Is this the same way to execute it on PostgreSQL and even I am not able to find SqlParameter i.e. new SqlParameter("id", id) do I need to install any package for same ?

  • User Avatar
    0
    alper created
    Support Team Director

    according to the Microsoft docs it supports SqlParameters

    https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.relationaldatabasefacadeextensions.executesqlrawasync?view=efcore-5.0#Microsoft_EntityFrameworkCore_RelationalDatabaseFacadeExtensions_ExecuteSqlRawAsync_Microsoft_EntityFrameworkCore_Infrastructure_DatabaseFacade_System_String_System_Object___

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09