asp.net-core-2.0

Entity Framework Core 2.1 throwing ArgumentException on left join

瘦欲@ 提交于 2019-12-21 15:18:14
问题 I recently upgraded my project from .NET Core 2.0 to 2.1. I use Entity Framework Core and have several LINQ expressions that include left joins. The following code is an example: var tickets = (from ticket in dbContext.Tickets join member in dbContext.Members on ticket.MemberID equals member.ID into memberLEFT from member in memberLEFT.DefaultIfEmpty() join memberType in dbContext.MemberTypes on member.MemberTypeID equals memberType.ID into memberTypeLEFT from memberType in memberTypeLEFT

How to change the default controller and action in ASP.NET Core API?

淺唱寂寞╮ 提交于 2019-12-21 04:35:15
问题 I'm creating an ASP.NET Core API app, and currently, and when one creates a new project there is a controller named Values, and by default the API opens it when you run. So, I deleted that controller and added a new controller named Intro, and inside it an action named Get. In the Startup.cs file, I have the following lines of code: app.UseMvc(opt => { opt.MapRoute("Default", "{controller=Intro}/{action=Get}/{id?}"); }); And my Intro controller looks like this: [Produces("application/json")]

Unit test AuthorizationHandler

我的梦境 提交于 2019-12-21 03:55:28
问题 I used the resource based authorization pattern in .NET Core 2.1 as described here. The only problem that I have is I have no idea on how to test my AuthorizationHandler cleanly. Anyone here did something like that already? AuthorizationHandler sample (from the above link): public class DocumentAuthorizationHandler : AuthorizationHandler<SameAuthorRequirement, Document> { protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, SameAuthorRequirement requirement,

ASP.Net Core 2 error handling: How to return formatted exception details in Http Response?

假如想象 提交于 2019-12-21 03:32:48
问题 I am looking for a way to return the details of any exception that occur when calling a method of my web API. By default in production environment, error 500 "Internal Server Error" is the only information returned by the API. It is a private API that is not published over the internet, and the caller application needs to get and store all details in case of exception. The exception details could be JSON formatted in the HttpResponse content, allowing the caller to read the Message attribute,

How to add external assembly (.dll) to .NET Core 2.0 on Visual Studio Code

一曲冷凌霜 提交于 2019-12-20 19:55:28
问题 I faced some issues regarding adding an external assembly ( .dll ) to my .NET Core 2.0 console application on Visual Studio Code as there are little to none documentation about how you can do it. Microsoft provides a very good tutorial about how one can add NuGet Packages and Project to project references, but no information on how to add external dlls . 回答1: After some research I managed to get it working. Open your .csproj file Below </PropertyGroup> tag, add <ItemGroup> <Reference Include=

How to deploy Angular 6 with .NET Core 2.0 Web API Application to Microsoft Azure?

一曲冷凌霜 提交于 2019-12-20 14:17:11
问题 How to deploy Angular 6 with .NET Core 2.0 Web API Application to Microsoft Azure? I have created ASP.NET Core 2.0 Web API (Server-Side app) application and inside that created Angular 6.0 app (Client-Side app). Both apps are build and running successfully in a local environment (Database - MongoDB: mLab server). Now, I want to deploy an angular app with .net core web API app to Azure environment in a single web app service (where client app and server app (web API) will serve). However, I

Dependency injection duplication in Controller and BaseController in .Net Core 2.0

人走茶凉 提交于 2019-12-20 12:52:14
问题 If I create a BaseController in my Asp.Net Core 2.0 web application that capsulizes some of the common dependencies are they still necessary in the actual controllers. For Example, the standard Account and Manage controllers in a default MVC 6 web application. public class AccountController : Controller { private readonly UserManager<ApplicationUser> _userManager; private readonly SignInManager<ApplicationUser> _signInManager; private readonly IEmailSender _emailSender; private readonly

Entityframework core 2.0 how to map Many-to-Many without creating a join table

試著忘記壹切 提交于 2019-12-20 07:32:13
问题 I am trying this activity to clone from existing .edmx project to code first. I have two entities. I want to have many to many relation without creating a new table. I am using EF Core 2.0 code first approach. Please find below the entity i have created. I am not sure whether is this is the right way to do this. I would like to have the foreign key column on both the tables ie. WorkflowId and WorkCaseId on WorkCase and Workflow tables respectively. public class WorkCase { [Key] public int

Entity Framework insert conflicts with another foreign key

泄露秘密 提交于 2019-12-20 06:32:42
问题 I am having difficulty inserting data with its related entities. public class Status : Entity, IAggregateRoot { //other properties public readonly List<Video> _videos; public readonly List<Photo> _photos; } -- public class Log : Entity, IAggregateRoot { //other properties public readonly List<Video> _videos; public readonly List<Photo> _photos; public readonly List<Sound> _audios; } -- public class Photo : Entity, IAggregateRoot { //other properties public string Type { get; set; } public int

Why is this basic ajax call giving me a 400 and not firing to the controller?

好久不见. 提交于 2019-12-20 06:04:10
问题 This is only a problem for me in my newest dot net core 2 web app, it works in previous dot net apps with no issue. I have a custom javascript file with paths to various servers that my site is hosted on(mainly dev, test, live). My ajax call looks like the following: var gameid = '@Html.Raw(Model.Id)'; $.ajax({ type: 'GET', url: url() + "UserGames/HasGame?id=" +gameid, cache: false, success: function (data) { console.log(data); }, error: function (req, status, err) { console.log('Something