草庐IT

core-text

全部标签

c# - 如何获取 ASP.NET Core 中所有路由的列表?

在ASP.NETCore中,有没有办法查看Startup中定义的所有路由的列表?我们正在使用IRouteBuilder的MapRoute扩展方法来定义路由。我们正在迁移一个较旧的项目WebAPI项目。在那里我们可以使用GlobalConfiguration.Configuration.Routes来获取所有路由。更具体地说,我们在Action过滤器中执行此操作。publicclassMyFilter:ActionFilterAttribute{publicoverridevoidOnActionExecuting(ActionExecutingContextactionContext)

c# - 如何在asp.net core中编写自定义actionResult

在webApi2中,我可以通过继承IHttpActionResult来编写自定义ActionResult。示例:publicclassMenivaActionResult:IHttpActionResult{privatereadonlyHttpRequestMessage_request;privatereadonlyServiceResponseBase_response;publicMenivaActionResult(HttpRequestMessagerequest,ServiceResponseBaseresponse){_request=request;_response

c# - Asp.net Core 2 API POST 对象为 NULL?

我有一个带有一些测试功能的.netCore2API设置。(VisualStudio2017)我使用postman将原始数据发送到该方法,但模型只是空白?为什么?//POSTapi/Product/test[HttpPost][Route("test")]publicobjecttest(MyTestModelmodel){try{vara=model.SomeTestParam;returnOk("Yey");}catch(Exceptionex){returnBadRequest(new{message=ex.Message});}}publicclassMyTestModel{pu

c# - 在 Entity Framework Core 2.0 中执行 SQL 命令删除表中的所有数据

我想从EntityFrameworkCore2.0执行SQL命令,但我不知道该怎么做。1.-我需要这样做的原因是我想从数据库表中删除所有数据,使用Context.remove或Context.removeRange会产生对数据库的许多调用(一个用于表中的每个数据)。2.-我读到有一种方法.ExecuteSqlCommand可以完成该操作,但是我的Context.Database中没有该方法(也许在Core2.0中它被删除了?)。这是信息的来源:DroppingtableInEntityFrameworkCoreandUWP因此,基本上我需要使用EFCore2.0从代码中删除一个表,据我

c# - ASP.NET Core 2 中多个相同类型实例的依赖注入(inject)

在ASP.NETCore2WebApi中,我想使用依赖注入(inject)来注入(inject)httpClientAHttpClient的实例至ControllerA,和一个实例httpClientB的HttpClient至ControllerB.DI注册代码如下所示:HttpClienthttpClientA=newHttpClient();httpClientA.BaseAddress=endPointA;services.AddSingleton(httpClientA);HttpClienthttpClientB=newHttpClient();httpClientB.Bas

c# - 执行存储过程时,使用 CommandType.StoredProcedure 与使用 CommandType.Text 相比有什么好处?

所以在C#中使用存储过程我有如下代码(省略连接代码):stringsql="GetClientDefaults";SqlCommandcmd=newSqlCommand(sql);cmd.CommandType=CommandType.StoredProcedure;//其中sql是存储过程的名称。现在,无论有没有注释行,这段代码似乎都能正常工作。那么,我需要这条线吗?设置这个是否有一些性能(或其他)好处?不设置它或将其设置为文本有好处吗? 最佳答案 根据thisblogpost中的测试当您使用CommandType.Text时,S

c# - 数据类型 text 和 varchar 在 C# 中的等于运算符中不兼容

我正在尝试从employeeTable访问数据empname,但我编写的代码出现以下错误:Thedatatypestextandvarcharareincompatibleintheequaltooperator.请提出解决方案privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse){stringConnection="DataSource=(local);Initialcatalog=Test;IntegratedSecurity=true";stringQuery="SELECT*FROMEmployeeT

c# - 如何在 .NET Core MVC 项目中转换 appsettings.json?

我已经在我的项目中添加了额外的json配置文件appsettings.DEV.jsonappsettings.QA.json并根据环境将它们加载到Startup函数中:publicStartup(IHostingEnvironmentenv){varbuilder=newConfigurationBuilder().SetBasePath(env.ContentRootPath).AddJsonFile("appsettings.json",optional:false,reloadOnChange:true).AddJsonFile($"appsettings.{env.Enviro

c# - 集成测试 ASP.NET Core Web API 和 EF Core 时重新配置依赖项

我正在学习本教程IntegrationTestingwithEntityFrameworkCoreandSQLServer我的代码是这样的集成测试类publicclassControllerRequestsShould:IDisposable{privatereadonlyTestServer_server;privatereadonlyHttpClient_client;privatereadonlyYourContext_context;publicControllerRequestsShould(){//ArrangevarserviceProvider=newServiceCo

c# - ASP.NET Core MVC 混合路由/FromBody 模型绑定(bind)和验证

我正在使用ASP.NETCore1.1MVC构建JSONAPI。给定以下模型和操作方法:publicclassTestModel{publicintId{get;set;}[Range(100,999)]publicintRootId{get;set;}[Required,MaxLength(200)]publicstringName{get;set;}publicstringDescription{get;set;}}[HttpPost("/test/{rootId}/echo/{id}")]publicIActionResultTestEcho([FromBody]TestMode