感謝您的觀察,我確實將它們應用了以下代碼,但在測試api之后未返回任何數據。我什至用我的連接字符串代替dbcontext還是一無所有!當閱讀器關閉且閱讀器處于打開狀態時,我收到此錯誤無效的調用FieldCount的嘗試。我在這種情況下已有一周的時間了,任何幫助。FromSql查詢僅返回單個表的實體。我的存儲過程帶有一個參數,并具有4個表的聯接。我已經嘗試使用“ ExecuteSqlCommand”查詢,因為結果是-1。using System.Threading.Tasks;using Microsoft.AspNetCore.Mvc;using ActivaMobileAgent.Persistence;using Microsoft.EntityFrameworkCore;using ActivaMobileAgent.Model;using System.Linq;using System.Collections.Generic;using System.Data.SqlClient;using System;using Dapper;using System.Data;using System.Data.Common; namespace ActivaMobileAgent.Controllers{ [Route("/api/Policy")] public class PolicyController : Controller { private readonly ActivaMobileAgentDbContext context; public PolicyController(ActivaMobileAgentDbContext context) => this.context = context; public readonly string connectionString = "Data Source=Localhost;Initial Catalog=HELLOxx;User=sa; Password=Helloxx"; [HttpGet("{id}")] public async Task<IActionResult> GetPolicy(string id) { using (var connection = new SqlConnection("Data Source=Localhost;Initial Catalog=Helios;User=sa; Password=P@ssw0rd")) { SqlCommand command = new SqlCommand(); command.Connection = connection; command.CommandType = System.Data.CommandType.StoredProcedure; command.CommandText ="dbo.sproc_Contract_Get"; command.Parameters.Add(new SqlParameter("@ContractNumber", SqlDbType.VarChar) { Value = id }); connection.Open(); using (var result = await command.ExecuteReaderAsync()) { return Json(result); } } }}}
- 2 回答
- 0 關注
- 140 瀏覽
添加回答
舉報
0/150
提交
取消