Read here about Kontext's Cookie and Privacy policy. Dismiss

Migrating from ASP.NET Core 1.x to ASP.NET Core 2.0 – Issues Continued

607 views 0 comments last modified about 9 months ago Raymond

In this page

Other related issues are found during my migration.

Unable to Change Identity Table Names

https://stackoverflow.com/questions/46118930/unable-to-change-asp-identity-table-names-asp-net-core-2

I faced the same issue as the above post. To fix it, I need to derive my database context with all the parameters specified:

public sealed class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, int, IdentityUserClaim<int>, IdentityUserRole<int>, IdentityUserLogin<int>, ApplicationRoleClaim, IdentityUserToken<int>>

.Net Core 2.0 Web API OpenIddict Authorization: redirecting to login instead of returning JSON data

https://stackoverflow.com/questions/45784814/net-core-2-0-web-api-openiddict-authorization-redirecting-to-index-instead-of

Changed the following code in Startup.cs

// Register the OAuth2 validation handler as required by oidc
             services.AddAuthentication().AddOAuthValidation();

To:

// Register the OAuth2 validation handler as required by oidc
             services.AddAuthentication(options =>
             {
                 options.DefaultAuthenticateScheme = OAuthValidationDefaults.AuthenticationScheme;
             }).AddOAuthValidation();

The property 'Roles' is not a navigation property of entity type 'ApplicationUser'. The 'Include(string)' method can only be used with a '.' separated list of navigation property names. or

The property 'Users' is not a navigation property of entity type 'ApplicationRole'. The 'Include(string)' method can only be used with a '.' separated list of navigation property names.

Based on the suggestions from Microsoft Docs, I added the navigation propertied back as suggested but now I am getting these errors. In EntityFramework Core 2.0, Fluent API has not implemented many to many relationships. The example given in the office documentation will define role and user relationship as one to many and one extra field can be added to your database model. So eventually I have decided to use ApplicationUserRole to do the work.

Define a custom class first:

public class ApplicationUserRole : IdentityUserRole<int>
     {
         public virtual ApplicationRole Role { get; set; }

        public virtual ApplicationUser User { get; set; }
     }

In Application Role, remove the Users navigation property added previously with the following:

#region  asp.net core 2.0 support
         /// <summary>
         /// Navigation property for the claims this role possesses.
         /// </summary>
         public virtual ICollection<ApplicationRoleClaim> Claims { get; set; }

        public virtual ICollection<ApplicationUserRole> UserRoles { get; set; }
         #endregion

In Application User, remove the Roles navigation property added previously with the following:

#region  asp.net core 2.0 support
         /// <summary>
         /// Navigation property for the claims this user possesses.
         /// </summary>
         public virtual ICollection<IdentityUserClaim<int>> Claims { get; set; }
         /// <summary>
         /// Navigation property for this users login accounts.6
         /// </summary>
         public virtual ICollection<IdentityUserLogin<int>> Logins { get; set; }

        public virtual ICollection<ApplicationUserRole> UserRoles { get; set; }
         #endregion

In all my projects, I then changed to use UserRoles to find all the users in one role or vice versa. This is the only way I found it work to migrate.

After more than one day’s work, I have now finally migrated my asp.net core 1.1 web application to asp.net core 2.0 with OIDC server integrated as well.

Related pages

Issue - Unable to get property 'apply' of undefined or null reference occurred in Angular 4.*, VS2017 15.3, ASP.NET Core 2.0

5722 views   10 comments last modified about 2 years ago

Issue Context After installed Visual Studio 2017 15.3 preview and .net core 2.0 preview SDK, I upgraded one of my existing asp.net core project to 2.0. The project was created using ‘dotnet new angular’ SPA template.&nbsp; I also upgraded all the client app packages to the latest. For exa...

View detail

Tuples in C# (4.x, 7.0, 7.1)

61 views   0 comments last modified about 3 months ago

What is a tuple? Tuple is an ordered sequence, fixed-size, immutable and of heterogeneous objects. Tuple has been existing in other languages such as F#, Python, Perl and etc. for a long time. It was first introduced into C# from C# 4.0 and has been evolving over time. Since C# 7.1, tuple...

View detail

Tuples in C# (4.x, 7.0, 7.1)

61 views   0 comments last modified about 3 months ago

What is a tuple? Tuple is an ordered sequence, fixed-size, immutable and of heterogeneous objects. Tuple has been existing in other languages such as F#, Python, Perl and etc. for a long time. It was first introduced into C# from C# 4.0 and has been evolving over time. Since C# 7.1, tuple...

View detail

C# version history and core features

64 views   0 comments last modified about 4 months ago

C# is my favourite programming language and has been evolving overtime. I have been programming with many other languages but C# is always my favourite because it is simple and easy to use. Visual Studio is the most powerful tool I’ve ever used. To me, programming efficiency and peformance are th...

View detail

Invoke Hadoop WebHDFS APIs in .NET Core

98 views   0 comments last modified about 3 months ago

Background Apache doesn't provide native official .NET APIs for Hadoop HDFS. The HTTP REST API supports the complete FileSystem / ...

View detail

Invoke Hadoop WebHDFS APIs in .NET Core

98 views   0 comments last modified about 3 months ago

Background Apache doesn't provide native official .NET APIs for Hadoop HDFS. The HTTP REST API supports the complete FileSystem / ...

View detail

Add comment

Please login first to add comments.  Log in New user?  Register

Comments (0)

No comments yet.