TIMESTAMP(7) with Time Zone to DateTimeOffset? System.InvalidCastException: Specified cast is not valid.
TIMESTAMP(7) with Time Zone to DateTimeOffset? System.InvalidCastException: Specified cast is not valid.
Hi,
I am implementing ASP.NET IDENTITY with Oracle 12C and using the following versions:
1. Microsoft.AspNetCore.Identity.EntityFrameworkCore: 1.1.0
2. dotConnect for Oracle Developer version 9.2.205
When one of the columns (LOCKOUT_END) in Table ASPNET_USERS contains a value it is unable to map to the entity class and throws the following exception: System.InvalidCastException: Specified cast is not valid.
The column type for LOCKOUT_END is TIMESTAMP(7) WITH TIME ZONE and the Model property is of type DateTimeOffset?
Is this not supported?
Thanks in advance
I am implementing ASP.NET IDENTITY with Oracle 12C and using the following versions:
1. Microsoft.AspNetCore.Identity.EntityFrameworkCore: 1.1.0
2. dotConnect for Oracle Developer version 9.2.205
When one of the columns (LOCKOUT_END) in Table ASPNET_USERS contains a value it is unable to map to the entity class and throws the following exception: System.InvalidCastException: Specified cast is not valid.
The column type for LOCKOUT_END is TIMESTAMP(7) WITH TIME ZONE and the Model property is of type DateTimeOffset?
Is this not supported?
Thanks in advance
Re: TIMESTAMP(7) with Time Zone to DateTimeOffset? System.InvalidCastException: Specified cast is not valid.
dotConnect for Oracle supports ASP.NET Identity 2.0 with EF6: https://www.devart.com/dotconnect/oracl ... ntity.html.
If this is not the case, please specify the version of ASP.NET Identity you are using.
If this is not the case, please specify the version of ASP.NET Identity you are using.
Re: TIMESTAMP(7) with Time Zone to DateTimeOffset? System.InvalidCastException: Specified cast is not valid.
Hi Shalex,Shalex wrote:dotConnect for Oracle supports ASP.NET Identity 2.0 with EF6: https://www.devart.com/dotconnect/oracl ... ntity.html.
If this is not the case, please specify the version of ASP.NET Identity you are using.
I am using ASP.NET Identity Core 1.1.0 with Entity Framework Core 1.1.0.
Thanks,
David
Re: TIMESTAMP(7) with Time Zone to DateTimeOffset? System.InvalidCastException: Specified cast is not valid.
We will investigate the question and notify you about the result as soon as possible.
Re: TIMESTAMP(7) with Time Zone to DateTimeOffset? System.InvalidCastException: Specified cast is not valid.
We are working on the walkthrough how to use ASP.NET Core Identity with Devart provider.
Could you please tell us the exact steps we should follow to reproduce the error in our environment?trand wrote:When one of the columns (LOCKOUT_END) in Table ASPNET_USERS contains a value it is unable to map to the entity class and throws the following exception: System.InvalidCastException: Specified cast is not valid.
Re: TIMESTAMP(7) with Time Zone to DateTimeOffset? System.InvalidCastException: Specified cast is not valid.
If LOCKOUT_END in table ASPNET_USERS has a value then you will receive an error. The easiest way to generate a value in LOCKOUT_END is to:Shalex wrote:We are working on the walkthrough how to use ASP.NET Core Identity with Devart provider.
Could you please tell us the exact steps we should follow to reproduce the error in our environment?trand wrote:When one of the columns (LOCKOUT_END) in Table ASPNET_USERS contains a value it is unable to map to the entity class and throws the following exception: System.InvalidCastException: Specified cast is not valid.
1. update a specific user record and set the LOCKOUT_END to a value in the future
2. Attempt to login with that same user
3. you will get a cast error
Alternatively you can generate a value for LOCKOUT_END by logging in with an account multiple times with a WRONG password until LOCKOUT_END generates a value (this usually occurs 5 times by default). This is done by ensuring and running the following ...
1. Make sure lockoutOnFailure is set to true and use this in your login controller action
var result = await _signInManager.PasswordSignInAsync(loginViewModel.username, loginViewModel.Password, loginViewModel.RememberMe, lockoutOnFailure: true);
2. Sign in with the wrong password multiple times. The column ACCESS_FAILED_COUNT will increment and once it reaches 5 it will lock the account by setting the LOCKOUT_END field.
3. you will get a cast error
Re: TIMESTAMP(7) with Time Zone to DateTimeOffset? System.InvalidCastException: Specified cast is not valid.
Thank you for the details. We will notify you about the result of our investigation.
Re: TIMESTAMP(7) with Time Zone to DateTimeOffset? System.InvalidCastException: Specified cast is not valid.
The compatibility with ASP.NET Core Identity is improved in the new version dotConnect for Oracle 9.4: viewtopic.php?f=1&t=35436.
Simple walkthrough with a new version:
* create File > New > Project > Installed > Visual C# > Web > ASP.NET Core Web Application (.NET Core), select Web Application and set Authentication: Individual User Accounts
* run via Package Manager Console
PM> install-package Devart.Data.Oracle.EFCore
* replace
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
with
options.UseOracle(Configuration.GetConnectionString("DefaultConnection")));
in Startup.cs
* set your DefaultConnection for Oracle in appsettings.json
* execute via Package Manager Console
PM> update-database
Simple walkthrough with a new version:
* create File > New > Project > Installed > Visual C# > Web > ASP.NET Core Web Application (.NET Core), select Web Application and set Authentication: Individual User Accounts
* run via Package Manager Console
PM> install-package Devart.Data.Oracle.EFCore
* replace
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
with
options.UseOracle(Configuration.GetConnectionString("DefaultConnection")));
in Startup.cs
* set your DefaultConnection for Oracle in appsettings.json
* execute via Package Manager Console
PM> update-database
Re: TIMESTAMP(7) with Time Zone to DateTimeOffset? System.InvalidCastException: Specified cast is not valid.
In case of "lockoutOnFailure: true", by default string properties are mapped to NCLOB.
There are two alternative ways to solve the issue:
1. Configuration options ->
2. Steps to implement manually ->
* remove default migrations files
* map explicitly string columns (except for ones which participate in PK) to set limits of length
* create a new migration with a new mapping (add-migration MIGRATION_NAME)
* apply the newly created migration (update-database)
There are two alternative ways to solve the issue:
1. Configuration options ->
Code: Select all
var config = Devart.Data.Oracle.Entity.Configuration.OracleEntityProviderConfig.Instance;
config.CodeFirstOptions.UseNonLobStrings = true;
config.CodeFirstOptions.UseNonUnicodeStrings = true;
* remove default migrations files
* map explicitly string columns (except for ones which participate in PK) to set limits of length
* create a new migration with a new mapping (add-migration MIGRATION_NAME)
* apply the newly created migration (update-database)