简体   繁体   中英

EF Core 3.1 executesqlInterpolated, how to add out parameter in the query

I expect the EF query below to get the total number of rows through the output parameter total , but it doesn't achieve this goal at the moment. How can I re-write this query to get the correct output back?

        _dbContext
            .Database
            .ExecuteSqlInterpolated($@"select {total} = count(*) 
                                        from SomeDbSet
                                        where ( columnA like '%{searchedValue1}%' 
                                            or columnB like '%{searchedValue2}%')");

You need to declare the total as an output SqlParameter before you can use it in the interpolated query.

        SqlParameter total = new SqlParameter()
        {
            ParameterName = "@Total",
            SqlDbType = SqlDbType.Int,
            Direction = ParameterDirection.Output
        };

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