.net-core-2.2

Core API Controller to catch all unknown routes

蹲街弑〆低调 提交于 2020-08-26 05:47:43
问题 I have a Core 2.2 API with a bunch of existing controllers. What i am now trying to do is add a new controller that acts similar to a catchall route, but only for that controller (and doesn't disturb the routes of the existing controllers) . In my existing controller i am defining the routes as controller attributes [Route("api/[controller]")] [ApiController] public class SandboxController : ControllerBase { [HttpGet("Hello")] public IEnumerable<string> Hello() { return new string[] { "Hello

C# Entity Framework: Linq Filter on GrandChildren and Conduct a Select on the Parent with Attributes

烈酒焚心 提交于 2020-06-29 03:42:31
问题 Our company is currently using Entity Framework Net Core 2.2 with Sql Server Trying to find all Distinct customers who purchased a certain Product Input Parameter . The following EF Linq query was written to get the distinct Customers. Later another question came up, how do we get more (navigation) properties of customer? Should Include be placed Before the Where or After the Where? Does it matter? When running the SQL Profiler, it noted no difference in the queries. I just wanted to be sure

C# Entity Framework: Linq Filter on GrandChildren and Conduct a Select on the Parent

て烟熏妆下的殇ゞ 提交于 2020-06-28 06:41:21
问题 Our company is currently using Entity Framework Net Core 2.2 with Sql Server Trying to find all Distinct customers who purchased a certain Product Input Parameter. When trying to do final select, it shows b lambda as Product. We need the Distinct Customers showing up last. How the EF Linq query be written to get this for distinct Customers? var taxAgencyDistinctList = db.Customer .SelectMany(b => b.Transactions) .SelectMany(b => b.Purchases) .Select(b => b.Product) .Where(b => b.BKProduct ==

Populate IConfiguration for unit tests

狂风中的少年 提交于 2020-05-28 14:18:06
问题 .NET Core configuration allows so many options to add values (environment variables, json files, command line args). I just can't figure out and find an answer how to populate it via code. I am writing unit tests for extension methods to configurations and I thought populating it in the unit tests via code would be easier than loading dedicated json files for each test. My current code: [Fact] public void Test_IsConfigured_Positive() { // test against this configuration IConfiguration config

Unable to run commands. Error: No database provider has been configured for this DbContext

我只是一个虾纸丫 提交于 2020-03-22 09:05:08
问题 I am unable to run EntityFramework Core commands against the basic .NET Core 2.2 Web API I created. The API is working, but I can not 'add-migration' or 'update-database' unless I change where the connection string is retrieved. I believe the first example is best practice because the connection string is more secure, but I get an error when trying to run EF Core commands. "No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext

.net core 3 yields different floating point results from version 2.2

旧街凉风 提交于 2020-03-16 07:28:46
问题 Here is a sample piece of code with outputs from .net core 2.2 and 3.1. It shows different computational results for a basic floating point expression a^b. In this example we calculate 1.9 to the power of 3. Previous .NET frameworks yielded the correct result, but .net core 3.0 and 3.1 yields a different result. Is this an intended change and how can we migrate financial calculation code to the new version with a guarantee that numerical calculations will still yield the same results? (It

.NET Core DI resolving keyed services using custom delegate returns null

半城伤御伤魂 提交于 2020-03-04 04:55:42
问题 I am struggling with a weird case. I have a .NET Core console application that is setup like this: private static async Task Main(string[] args) { var runAsService = !(Debugger.IsAttached || args.Contains("console")); var builder = new HostBuilder() .ConfigureServices((hostContext, services) => { services.AddLogging(loggingBuilder => { loggingBuilder.AddConsole(); }); services.AddGatewayServers(); services.AddHostedService<GatewayService>(); }); if (runAsService) await builder.RunServiceAsync

.net core 2.2 multiple bearer token authentication schemes

二次信任 提交于 2020-02-25 13:12:06
问题 I am currently trying to use 2 different bearer tokens in a .net core 2.2 app. I would like to use an Identity Server token and an Azure AD bearer token. According to Microsoft this is possible (https://docs.microsoft.com/en-us/aspnet/core/security/authorization/limitingidentitybyscheme?view=aspnetcore-2.2) but I am having no success getting it working. I have the Identity Server token as the "default" authentication followed by the AzureAD token as documented in the aforementioned link:

Select correct Angular Environment based on .Net Core build

丶灬走出姿态 提交于 2020-02-02 02:14:05
问题 I created an .Net Core Web Api with an Angular ClientApp with the templates from Visual Studio. When building the project also builds the contained Angular App with the params set in the .csproj <Target> section e.g. <Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish"> <!-- As part of publishing, ensure the JS resources are freshly built in production mode --> <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" /> <Exec WorkingDirectory="$(SpaRoot)" Command="npm run

.Net Core warning No XML encryptor configured

拜拜、爱过 提交于 2020-02-01 00:35:09
问题 When I start my service (API on .Net Core 2.2 in Docker container) I've got a warning: No XML encryptor configured. Key {daa53741-8295-4c9b-ae9c-e69b003f16fa} may be persisted to storage in unencrypted form. I didn't configure DataProtection. I've found solutions to configure DataProtection but I don't need to save this key. For me if the key will only be persisted until the application restarts - it's Ok. But I don't need to see this warning in logs Any ideas? How can we do it? My startup