Page 1 of 1

TIMESTAMP(7) with Time Zone to DateTimeOffset? System.InvalidCastException: Specified cast is not valid.

Posted: Wed 15 Feb 2017 23:54
by trand
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

Re: TIMESTAMP(7) with Time Zone to DateTimeOffset? System.InvalidCastException: Specified cast is not valid.

Posted: Mon 20 Feb 2017 16:16
by Shalex
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.

Re: TIMESTAMP(7) with Time Zone to DateTimeOffset? System.InvalidCastException: Specified cast is not valid.

Posted: Tue 21 Feb 2017 17:29
by trand
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.
Hi Shalex,

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.

Posted: Tue 28 Feb 2017 18:46
by Shalex
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.

Posted: Fri 03 Mar 2017 16:01
by Shalex
We are working on the walkthrough how to use ASP.NET Core Identity with Devart provider.
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.
Could you please tell us the exact steps we should follow to reproduce the error in our environment?

Re: TIMESTAMP(7) with Time Zone to DateTimeOffset? System.InvalidCastException: Specified cast is not valid.

Posted: Fri 03 Mar 2017 21:56
by trand
Shalex wrote:We are working on the walkthrough how to use ASP.NET Core Identity with Devart provider.
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.
Could you please tell us the exact steps we should follow to reproduce the error in our environment?
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:

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.

Posted: Mon 06 Mar 2017 11:58
by Shalex
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.

Posted: Fri 26 May 2017 20:06
by Shalex
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

Re: TIMESTAMP(7) with Time Zone to DateTimeOffset? System.InvalidCastException: Specified cast is not valid.

Posted: Wed 02 Aug 2017 17:57
by Shalex
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 ->

Code: Select all

var config = Devart.Data.Oracle.Entity.Configuration.OracleEntityProviderConfig.Instance;
config.CodeFirstOptions.UseNonLobStrings = true;
config.CodeFirstOptions.UseNonUnicodeStrings = true;
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)