简体   繁体   中英

ASP.Net Core - Entity Framework - Call Stored Procedure With No Return Data (in a void method)

I'm current using ASP.Net Core with Entity Framework 3.1.1. I want to just call a procedure as void instead of returning data. Here my current setup for calling procedures and fitting the data into a model.

public List<MyModel> GetData(int ID)
{
    var result = (from x in _dbContext.MyModel.FromSqlRaw("ustp_ProcedureName {0}", param1)
                  select x).ToList();

    return result;
}

How do I do use FromSqlRaw, but in a void method and with a procedure that doesn't return data?

To get data better to use this:

 var result = _dbContext.MyModel
                  .FromSqlRaw("ustp_ProcedureName {0}", param1)
                  .ToList();

if you want to run sp that doesnt return any data try this:


_dbContext.Database.ExecuteSqlCommand("ustp_ProcedureName {0}", param1);

You can call a stored procedure in your DbContext class as follows.

this.Database.SqlQuery("storedProcedureName",params);

ref: How to call Stored Procedure in Entity Framework 6 (Code-First)?

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