• <bdo id='TWM8C'></bdo><ul id='TWM8C'></ul>

      1. <i id='TWM8C'><tr id='TWM8C'><dt id='TWM8C'><q id='TWM8C'><span id='TWM8C'><b id='TWM8C'><form id='TWM8C'><ins id='TWM8C'></ins><ul id='TWM8C'></ul><sub id='TWM8C'></sub></form><legend id='TWM8C'></legend><bdo id='TWM8C'><pre id='TWM8C'><center id='TWM8C'></center></pre></bdo></b><th id='TWM8C'></th></span></q></dt></tr></i><div id='TWM8C'><tfoot id='TWM8C'></tfoot><dl id='TWM8C'><fieldset id='TWM8C'></fieldset></dl></div>
        <legend id='TWM8C'><style id='TWM8C'><dir id='TWM8C'><q id='TWM8C'></q></dir></style></legend>
        <tfoot id='TWM8C'></tfoot>

        <small id='TWM8C'></small><noframes id='TWM8C'>

        如何将 SQL 输出参数与 FromSqlInterpolated 一起使用?或替代

        时间:2023-06-25

          <small id='kdn85'></small><noframes id='kdn85'>

          <i id='kdn85'><tr id='kdn85'><dt id='kdn85'><q id='kdn85'><span id='kdn85'><b id='kdn85'><form id='kdn85'><ins id='kdn85'></ins><ul id='kdn85'></ul><sub id='kdn85'></sub></form><legend id='kdn85'></legend><bdo id='kdn85'><pre id='kdn85'><center id='kdn85'></center></pre></bdo></b><th id='kdn85'></th></span></q></dt></tr></i><div id='kdn85'><tfoot id='kdn85'></tfoot><dl id='kdn85'><fieldset id='kdn85'></fieldset></dl></div>

              <tbody id='kdn85'></tbody>
            1. <tfoot id='kdn85'></tfoot>
              • <legend id='kdn85'><style id='kdn85'><dir id='kdn85'><q id='kdn85'></q></dir></style></legend>

                  <bdo id='kdn85'></bdo><ul id='kdn85'></ul>
                • 本文介绍了如何将 SQL 输出参数与 FromSqlInterpolated 一起使用?或替代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  使用 ASP.Net 核心 3.0.我的数据库查询有效 - 我可以获得结果集(记录),但是如何传递/获取输出参数?也想知道有没有办法获取返回值.

                  Using ASP.Net core 3.0. my Database query works - I can get the result set (records), but how to pass/get the output parameter? Also would like to know if there's a way to get the return value.

                  我尝试使用不同的方法来调用 SQL 查询,唯一能够工作的是 FromSqlInterpolated,但对不同的方法开放.

                  I tried using different ways to call the SQL query and the only one I was able to get working was FromSqlInterpolated, but open to different methods.

                  这段代码对我有用,但我想传递一个可以作为输出参数填充的附加参数(当我通过从 SQL Server 中调用存储过程来测试它时,它可以工作).

                  This code works for me, but I want to pass an additional parameter that can get populated as an output parameter (which is working when I test it by calling the stored proc from within SQL Server).

                  var result = _context.Users
                          .FromSqlInterpolated($"EXEC mystoredproc  {user.Username} ").AsEnumerable().FirstOrDefault();
                  

                  我尝试在调用前创建一个变量

                  I tried creating a variable before the call

                  string out1 = null;
                  

                  然后在调用中包含它,但我无法弄清楚语法,我不确定此方法是否支持它.

                  And then including that in the call but I can't figure out the syntax and I'm not sure if it's supported with this method.

                  var result = _context.Users
                          .FromSqlInterpolated($"EXEC mystoredproc  {user.Username},  OUTPUT {out1}").AsEnumerable().FirstOrDefault();
                  Console.WriteLine(out1);
                  

                  希望有人能指出我正确的方向 - 想知道如何使用输出参数以及如何获取返回值,而不仅仅是记录集.谢谢.

                  Hoping someone can point me in the right direction - would like to know both how to use the output parameter and how to get the return value, not just the record set. Thank you.

                  推荐答案

                  接受的答案似乎对我不起作用.但是我终于设法通过使用以下代码使 OUTPUT 参数工作

                  The answer accepted does not seem to work for me. However I finally manage to have the OUTPUT parameter work by using the following code

                   var p0 = new SqlParameter("@userName", {user.Username});
                   var p1 = new SqlParameter("@out1", System.Data.SqlDbType.NVarChar, 20) { Direction = System.Data.ParameterDirection.Output };
                  
                   string out1 = null;
                   var result = _context.Users
                      .FromSqlRaw($"EXEC mystoredproc  @userName, @out1 OUTPUT ", p0, p1).AsEnumerable().FirstOrDefault();
                  
                   Console.WriteLine(p1.Value); // Contains the new value of the p1 parameter
                  

                  只是一个小警告,p1 值属性只会在请求被执行时改变(通过 AsEnumerableLoad() 或任何强制 Sql执行)

                  Just a litte warning, the p1 value property will be changed only when the request will be executed (by an AsEnumerable, Load() or anything that forces the Sql execution)

                  这篇关于如何将 SQL 输出参数与 FromSqlInterpolated 一起使用?或替代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在不使用实体框架的情况下从 .Net Core 连接到 SQL Server? 下一篇:AWS Lambda - 无法连接到 VPC 中的 SQL Server RDS

                  相关文章

                    <bdo id='ItUUq'></bdo><ul id='ItUUq'></ul>

                  <small id='ItUUq'></small><noframes id='ItUUq'>

                    <tfoot id='ItUUq'></tfoot>
                    <legend id='ItUUq'><style id='ItUUq'><dir id='ItUUq'><q id='ItUUq'></q></dir></style></legend>
                  1. <i id='ItUUq'><tr id='ItUUq'><dt id='ItUUq'><q id='ItUUq'><span id='ItUUq'><b id='ItUUq'><form id='ItUUq'><ins id='ItUUq'></ins><ul id='ItUUq'></ul><sub id='ItUUq'></sub></form><legend id='ItUUq'></legend><bdo id='ItUUq'><pre id='ItUUq'><center id='ItUUq'></center></pre></bdo></b><th id='ItUUq'></th></span></q></dt></tr></i><div id='ItUUq'><tfoot id='ItUUq'></tfoot><dl id='ItUUq'><fieldset id='ItUUq'></fieldset></dl></div>