简体   繁体   中英

How to call PostgreSQL stored procedure from EF Core?

I want to call a function I wrote from database but the result is -1 please help

Database : Postgresql

var result = _context.Database.ExecuteSqlRaw($"select * from subunit({unitId})");

Function class

[Keyless]
public  class SubUnit
{
 
    public string Unit { get; set; }
    
}

We added the following reference to the DbContext class

 public virtual DbSet<SubUnit> SubUnits { get; set; }

Called function code

    public IEnumerable<Unit> GetSubUnitByParentId(long unitId)
    {

        var result = _context.SubUnits.FromSqlInterpolated($"select * from subunit({unitId})");

     
        return result;
    }

its run succesfull.

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