An error during login process. Linq query can't be translated.
```
public override async Task
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
var userId = user.Id;
var query = from userRole in UserRoles
join role in Roles on userRole.RoleId equals role.Id
where userRole.UserId.Equals(userId)
select role.Name;
return await query.ToListAsync(cancellationToken);
}
That fragment is throwing an exception
Equivalent code that using database context works fine
var query =
from userRole in _mainContext.TblUserUserRole
join role in _mainContext.TblUserRole on userRole.UserRoleId equals role.UserRoleId
where userRole.UserId.Equals(user.UserId)
select role.Name;
var result = await query .ToListAsync();
### To Reproduce
```
public class TblUserUserRole : IdentityUserRole<int>
{
public int UserUserRoleId { get; set; }
public override int RoleId
{
get => UserRoleId.Value;
set => UserRoleId = value;
}
public override int UserId { get; set; }
public int? UserRoleId { get; set; }
public DateTime? EntryDt { get; set; }
public bool? Active { get; set; }
public TblUserRole UserRole { get; set; }
public TblUser User { get; set; }
}
```
public class TblUserRole : IdentityRole
{
public override int Id
{
get => UserRoleId;
set => UserRoleId = value;
}
public override string Name
{
get => UserRoleName;
set => UserRoleName = value;
}
public int UserRoleId { get; set; }
public string UserRoleName { get; set; }
public string UserRoleDescription { get; set; }
public int? UserRoleLevel { get; set; }
public bool? IsApplication { get; set; }
public string ApplicationName { get; set; }
public string ApplicationUrl { get; set; }
public DateTime? EntryDt { get; set; }
public DateTime? LastEditDt { get; set; }
public bool? Active { get; set; }
public ICollection<TblUserUserRole> UserUserRoles { get; set; }
}
Method used
var result = await _signInManager.PasswordSignInAsync(model.Username,
model.Password, model.RememberMe,
lockoutOnFailure: true);
Context implementation
public class IdentityContext : IdentityDbContext
int,
IdentityUserClaim
TblUserUserRole,
IdentityUserLogin
IdentityRoleClaim
IdentityUserToken
System.InvalidOperationException: The LINQ expression 'DbSet
.Join(
outer: DbSet
inner: t => t.RoleId,
outerKeySelector: t0 => t0.Id,
innerKeySelector: (t, t0) => new TransparentIdentifier
Outer = t,
Inner = t0
))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutorTResult
at Microsoft.EntityFrameworkCore.Storage.Database.CompileQueryTResult
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCoreTResult
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass12_01.<ExecuteAsync>b__0()
at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryTResult
at Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore9.GetRolesAsync(TUser user, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Identity.UserManager1.GetRolesAsync(TUser user)
at Microsoft.AspNetCore.Identity.UserClaimsPrincipalFactory2.GenerateClaimsAsync(TUser user)
at Microsoft.AspNetCore.Identity.UserClaimsPrincipalFactory1.CreateAsync(TUser user)
at IdentityServer4.AspNetIdentity.UserClaimsFactory1.CreateAsync(TUser user)
at Microsoft.AspNetCore.Identity.SignInManager1.CreateUserPrincipalAsync(TUser user)
at Microsoft.AspNetCore.Identity.SignInManager1.SignInWithClaimsAsync(TUser user, AuthenticationProperties authenticationProperties, IEnumerable1 additionalClaims)
at Microsoft.AspNetCore.Identity.SignInManager1.SignInOrTwoFactorAsync(TUser user, Boolean isPersistent, String loginProvider, Boolean bypassTwoFactor)
at Microsoft.AspNetCore.Identity.SignInManager1.PasswordSignInAsync(TUser user, String password, Boolean isPersistent, Boolean lockoutOnFailure)
at Microsoft.AspNetCore.Identity.SignInManager`1.PasswordSignInAsync(String userName, String password, Boolean isPersistent, Boolean lockoutOnFailure)
```
-->
dotnet --info:@ajcvickers Any idea what would cause this in EF?
@blowdart Either a bug or a consequence of customizing the identity model. We'll need a repro.
@LastImmort Can you provide a sample runnable repo?
@blowdart will try to do it tomorrow
Thanks!
@ajcvickers small repro is ready, the same error for inmemory db
SmallReproduceProject.zip
@smitpatel Any ideas on this. Full model is below.
Model:
EntityType: IdentityRoleClaim<int>
Properties:
Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd
Annotations:
SqlServer:ValueGenerationStrategy: IdentityColumn
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
ClaimType (string)
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
ClaimValue (string)
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
RoleId (int) Required FK Index
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
Keys:
Id PK
Foreign keys:
IdentityRoleClaim<int> {'RoleId'} -> TblUserRole {'UserRoleId'}
Annotations:
ConstructorBinding: Microsoft.EntityFrameworkCore.Metadata.ConstructorBinding
Relational:TableName: AspNetRoleClaims
EntityType: IdentityUserClaim<int>
Properties:
Id (int) Required PK AfterSave:Throw ValueGenerated.OnAdd
Annotations:
SqlServer:ValueGenerationStrategy: IdentityColumn
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
ClaimType (string)
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
ClaimValue (string)
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
UserId (int) Required FK Index
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
Keys:
Id PK
Foreign keys:
IdentityUserClaim<int> {'UserId'} -> TblUser {'UserId'}
Annotations:
ConstructorBinding: Microsoft.EntityFrameworkCore.Metadata.ConstructorBinding
Relational:TableName: AspNetUserClaims
EntityType: IdentityUserLogin<int>
Properties:
LoginProvider (string) Required PK AfterSave:Throw
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
ProviderKey (string) Required PK AfterSave:Throw
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
ProviderDisplayName (string)
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
UserId (int) Required FK Index
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
Keys:
LoginProvider, ProviderKey PK
Foreign keys:
IdentityUserLogin<int> {'UserId'} -> TblUser {'UserId'}
Annotations:
ConstructorBinding: Microsoft.EntityFrameworkCore.Metadata.ConstructorBinding
Relational:TableName: AspNetUserLogins
EntityType: IdentityUserToken<int>
Properties:
UserId (int) Required PK FK AfterSave:Throw
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
LoginProvider (string) Required PK AfterSave:Throw
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Name (string) Required PK AfterSave:Throw
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Value (string)
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Keys:
UserId, LoginProvider, Name PK
Foreign keys:
IdentityUserToken<int> {'UserId'} -> TblUser {'UserId'}
Annotations:
ConstructorBinding: Microsoft.EntityFrameworkCore.Metadata.ConstructorBinding
Relational:TableName: AspNetUserTokens
EntityType: TblUser
Properties:
UserId (int) Required PK Index AfterSave:Throw ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: UserID
SqlServer:ValueGenerationStrategy: IdentityColumn
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
AccessFailedCount (int) Required
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
AccountId (Nullable<int>) ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: AccountID
Relational:DefaultValueSql: ((1))
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
Active (Nullable<bool>) Index ValueGenerated.OnAdd
Annotations:
Relational:DefaultValueSql: ((1))
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
Address1 (string) MaxLength64 Ansi
Annotations:
MaxLength: 64
Relational:ColumnName: Address_1
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
Address2 (string) MaxLength64 Ansi
Annotations:
MaxLength: 64
Relational:ColumnName: Address_2
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
AssemblerId (Nullable<int>) Index ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: AssemblerID
Relational:DefaultValueSql: ((1))
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
City (string) MaxLength64 Ansi
Annotations:
MaxLength: 64
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
ClientId (Nullable<int>) Index ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: ClientID
Relational:DefaultValueSql: ((1))
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
CompanyId (Nullable<int>) Index ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: CompanyID
Relational:DefaultValueSql: ((1))
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
ConcurrencyStamp (string) Concurrency
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
CountryCode (string) MaxLength16 Ansi
Annotations:
MaxLength: 16
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
DeviceCarrier (string) Index MaxLength64 Ansi
Annotations:
MaxLength: 64
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
DeviceName (string) Index MaxLength64 Ansi
Annotations:
MaxLength: 64
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
DeviceOs (string) Index MaxLength64 Ansi
Annotations:
MaxLength: 64
Relational:ColumnName: DeviceOS
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
DeviceUid (string) MaxLength64 Ansi
Annotations:
MaxLength: 64
Relational:ColumnName: DeviceUID
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
DriverId (Nullable<int>) Index ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: DriverID
Relational:DefaultValueSql: ((1))
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
EmailAddress (string) Index MaxLength64 Ansi
Annotations:
MaxLength: 64
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
EmailConfirmed (bool) Required
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
EncryptedPassword (string) MaxLength128 Ansi
Annotations:
MaxLength: 128
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
EntryDt (Nullable<DateTime>) Index ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: EntryDT
Relational:ColumnType: datetime
Relational:DefaultValueSql: (getdate())
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDateTimeTypeMapping
EntryUserId (Nullable<int>) ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: EntryUserID
Relational:DefaultValueSql: ((0))
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
Fname (string) Index MaxLength64 Ansi
Annotations:
MaxLength: 64
Relational:ColumnName: FName
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
ForDelete (Nullable<bool>) Index
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
HasGpsloggedToday (bool) Required
Annotations:
Relational:ColumnName: HasGPSLoggedToday
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
HasTermsAgreed (bool) Required
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
HomePhone (string) Index MaxLength24 Ansi
Annotations:
MaxLength: 24
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
ImageUploaded (bool) Required Index
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
Interface (string) ValueGenerated.OnAdd MaxLength64 Ansi
Annotations:
MaxLength: 64
Relational:DefaultValueSql: ('Standard')
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
IsContractCarrier (bool) Required
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
LanguageCode (string)
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
LastEditDt (Nullable<DateTime>) Index
Annotations:
Relational:ColumnName: LastEditDT
Relational:ColumnType: datetime
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDateTimeTypeMapping
LastEditUserId (Nullable<int>) ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: LastEditUserID
Relational:DefaultValueSql: ((0))
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
LastEncryptedPassword (string)
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
LastUsedDt (Nullable<DateTime>) Index
Annotations:
Relational:ColumnName: LastUsedDT
Relational:ColumnType: datetime
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDateTimeTypeMapping
Lname (string) Index MaxLength64 Ansi
Annotations:
MaxLength: 64
Relational:ColumnName: LName
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
LockoutEnabled (bool) Required
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
LockoutEnd (Nullable<DateTimeOffset>)
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDateTimeOffsetTypeMapping
MobilePhone (string) Index MaxLength24 Ansi
Annotations:
MaxLength: 24
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
NormalizedEmail (string) Index MaxLength256
Annotations:
MaxLength: 256
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
NormalizedUserName (string) Index MaxLength256
Annotations:
MaxLength: 256
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
PasswordUpdatedDt (Nullable<DateTime>)
Annotations:
Relational:ColumnName: PasswordUpdatedDT
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDateTimeTypeMapping
PhoneNumberConfirmed (bool) Required
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
PostalCode (string) MaxLength16 Ansi
Annotations:
MaxLength: 16
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
SecretAnswer (string) MaxLength128 Ansi
Annotations:
MaxLength: 128
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
SecretQuestion (string) MaxLength128 Ansi
Annotations:
MaxLength: 128
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
SecurityStamp (string)
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
StateProvCode (string) MaxLength16 Ansi
Annotations:
MaxLength: 16
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
StoreId (Nullable<int>) ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: StoreID
Relational:DefaultValueSql: ((1))
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
TimeZoneCode (string) Index MaxLength5 Ansi
Annotations:
MaxLength: 5
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
TimeZoneId (Nullable<int>) ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: TimeZoneID
Relational:DefaultValueSql: ((1))
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
TwoFactorEnabled (bool) Required
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
UseAutoAssignAllAccounts (bool) Required
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
UseAutoAssignAllWarehouses (bool) Required
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
UseAutoDeactivate (bool) Required
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
UseMobileAppNotification (bool) Required
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
UserColor (string) Index ValueGenerated.OnAdd MaxLength16 Ansi
Annotations:
MaxLength: 16
Relational:DefaultValueSql: ([dbo].[fn_GenerateUserUniqueRandomHexColor]())
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
UserName (string) Required Index ValueGenerated.OnAdd MaxLength64 Ansi
Annotations:
MaxLength: 64
Relational:DefaultValueSql: ('')
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
UserPassword (string) Required Index ValueGenerated.OnAdd MaxLength64 Ansi
Annotations:
MaxLength: 64
Relational:DefaultValueSql: ('')
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
UserTypeId (int) Required FK Index
Annotations:
Relational:ColumnName: UserTypeID
Relational:DefaultValueSql: ((1))
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
UserUid (Guid) Required Index ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: UserUID
Relational:DefaultValueSql: (newid())
TypeMapping: Microsoft.EntityFrameworkCore.Storage.GuidTypeMapping
Navigations:
UserType (TblUserType) ToPrincipal TblUserType
UserUserGroups (ICollection<TblUserUserGroup>) Collection ToDependent TblUserUserGroup Inverse: User
UserUserRoles (ICollection<TblUserUserRole>) Collection ToDependent TblUserUserRole Inverse: User
Keys:
UserId PK
Foreign keys:
TblUser {'UserTypeId'} -> TblUserType {'UserTypeId'} ToPrincipal: UserType
Annotations:
ConstructorBinding: Microsoft.EntityFrameworkCore.Metadata.ConstructorBinding
Relational:TableName: tbl_User
EntityType: TblUserGroup
Properties:
UserGroupId (int) Required PK AfterSave:Throw ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: UserGroupID
SqlServer:ValueGenerationStrategy: IdentityColumn
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
Active (Nullable<bool>) ValueGenerated.OnAdd
Annotations:
Relational:DefaultValueSql: ((1))
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
ClientId (Nullable<int>) ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: ClientID
Relational:DefaultValueSql: ((1))
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
EntryDt (Nullable<DateTime>) ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: EntryDT
Relational:ColumnType: datetime
Relational:DefaultValueSql: (getdate())
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDateTimeTypeMapping
EntryUserId (Nullable<int>)
Annotations:
Relational:ColumnName: EntryUserID
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
ForDelete (Nullable<bool>)
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
IsBillingUserGroup (bool) Required
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
IsSystemUserGroup (bool) Required
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
LastEditDt (Nullable<DateTime>)
Annotations:
Relational:ColumnName: LastEditDT
Relational:ColumnType: datetime
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDateTimeTypeMapping
LastEditUserId (Nullable<int>)
Annotations:
Relational:ColumnName: LastEditUserID
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
LastUsedDt (Nullable<DateTime>)
Annotations:
Relational:ColumnName: LastUsedDT
Relational:ColumnType: datetime
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDateTimeTypeMapping
UserGroupDescription (string) MaxLength256 Ansi
Annotations:
MaxLength: 256
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
UserGroupName (string) MaxLength64 Ansi
Annotations:
MaxLength: 64
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
Navigations:
UserUserGroups (ICollection<TblUserUserGroup>) Collection ToDependent TblUserUserGroup Inverse: UserGroup
Keys:
UserGroupId PK
Annotations:
ConstructorBinding: Microsoft.EntityFrameworkCore.Metadata.ConstructorBinding
Relational:TableName: tbl_UserGroup
EntityType: TblUserRole
Properties:
UserRoleId (int) Required PK AfterSave:Throw ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: UserRoleID
SqlServer:ValueGenerationStrategy: IdentityColumn
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
Active (Nullable<bool>) ValueGenerated.OnAdd
Annotations:
Relational:DefaultValueSql: ((1))
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
ApplicationName (string) MaxLength64 Ansi
Annotations:
MaxLength: 64
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
ApplicationUrl (string) MaxLength256 Ansi
Annotations:
MaxLength: 256
Relational:ColumnName: ApplicationURL
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
ConcurrencyStamp (string) Concurrency
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
EntryDt (Nullable<DateTime>) ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: EntryDT
Relational:ColumnType: datetime
Relational:DefaultValueSql: (getdate())
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDateTimeTypeMapping
IsApplication (Nullable<bool>)
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
LastEditDt (Nullable<DateTime>)
Annotations:
Relational:ColumnName: LastEditDT
Relational:ColumnType: datetime
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDateTimeTypeMapping
NormalizedName (string) Index MaxLength256
Annotations:
MaxLength: 256
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
UserRoleDescription (string) MaxLength256 Ansi
Annotations:
MaxLength: 256
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
UserRoleLevel (Nullable<int>)
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
UserRoleName (string) Index MaxLength64 Ansi
Annotations:
MaxLength: 64
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
Navigations:
UserUserRoles (ICollection<TblUserUserRole>) Collection ToDependent TblUserUserRole Inverse: UserRole
Keys:
UserRoleId PK
Annotations:
ConstructorBinding: Microsoft.EntityFrameworkCore.Metadata.ConstructorBinding
Relational:TableName: tbl_UserRole
EntityType: TblUserType
Properties:
UserTypeId (int) Required PK AfterSave:Throw ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: UserTypeID
SqlServer:ValueGenerationStrategy: IdentityColumn
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
Active (Nullable<bool>) ValueGenerated.OnAdd
Annotations:
Relational:DefaultValueSql: ((1))
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
EntryDt (Nullable<DateTime>) ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: EntryDT
Relational:ColumnType: datetime
Relational:DefaultValueSql: (getdate())
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDateTimeTypeMapping
EntryUserId (Nullable<int>)
Annotations:
Relational:ColumnName: EntryUserID
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
ForDelete (Nullable<bool>)
Annotations:
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
LastEditDt (Nullable<DateTime>)
Annotations:
Relational:ColumnName: LastEditDT
Relational:ColumnType: datetime
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDateTimeTypeMapping
LastEditUserId (Nullable<int>)
Annotations:
Relational:ColumnName: LastEditUserID
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
UserTypeLevelNumber (int) Required ValueGenerated.OnAdd
Annotations:
Relational:DefaultValueSql: ((1))
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
UserTypeName (string) Required MaxLength32 Ansi
Annotations:
MaxLength: 32
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
UserTypeNote (string) MaxLength256 Ansi
Annotations:
MaxLength: 256
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerStringTypeMapping
Unicode: False
Keys:
UserTypeId PK
Annotations:
ConstructorBinding: Microsoft.EntityFrameworkCore.Metadata.ConstructorBinding
Relational:TableName: tbl_UserType
EntityType: TblUserUserGroup
Properties:
UserUserGroupId (int) Required PK AfterSave:Throw ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: User_UserGroup_ID
SqlServer:ValueGenerationStrategy: IdentityColumn
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
Active (Nullable<bool>) ValueGenerated.OnAdd
Annotations:
Relational:DefaultValueSql: ((1))
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
EntryDt (Nullable<DateTime>) ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: EntryDT
Relational:ColumnType: datetime
Relational:DefaultValueSql: (getdate())
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDateTimeTypeMapping
UserGroupId (Nullable<int>) FK Index
Annotations:
Relational:ColumnName: UserGroupID
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
UserId (Nullable<int>) FK Index
Annotations:
Relational:ColumnName: UserID
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
Navigations:
User (TblUser) ToPrincipal TblUser Inverse: UserUserGroups
UserGroup (TblUserGroup) ToPrincipal TblUserGroup Inverse: UserUserGroups
Keys:
UserUserGroupId PK
Foreign keys:
TblUserUserGroup {'UserGroupId'} -> TblUserGroup {'UserGroupId'} ToDependent: UserUserGroups ToPrincipal: UserGroup
TblUserUserGroup {'UserId'} -> TblUser {'UserId'} ToDependent: UserUserGroups ToPrincipal: User
Annotations:
ConstructorBinding: Microsoft.EntityFrameworkCore.Metadata.ConstructorBinding
Relational:TableName: tbl_User_UserGroup
EntityType: TblUserUserRole
Properties:
UserUserRoleId (int) Required PK AfterSave:Throw ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: User_UserRole_ID
SqlServer:ValueGenerationStrategy: IdentityColumn
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
Active (Nullable<bool>) ValueGenerated.OnAdd
Annotations:
Relational:DefaultValueSql: ((1))
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerBoolTypeMapping
EntryDt (Nullable<DateTime>) ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: EntryDT
Relational:ColumnType: datetime
Relational:DefaultValueSql: (getdate())
TypeMapping: Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDateTimeTypeMapping
UserId (int) Required FK Index ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: UserID
Relational:DefaultValueSql: ((0))
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
UserRoleId (Nullable<int>) FK Index ValueGenerated.OnAdd
Annotations:
Relational:ColumnName: UserRoleID
Relational:DefaultValueSql: ((0))
TypeMapping: Microsoft.EntityFrameworkCore.Storage.IntTypeMapping
Navigations:
User (TblUser) ToPrincipal TblUser Inverse: UserUserRoles
UserRole (TblUserRole) ToPrincipal TblUserRole Inverse: UserUserRoles
Keys:
UserUserRoleId PK
Foreign keys:
TblUserUserRole {'UserId'} -> TblUser {'UserId'} ToDependent: UserUserRoles ToPrincipal: User
TblUserUserRole {'UserRoleId'} -> TblUserRole {'UserRoleId'} ToDependent: UserUserRoles ToPrincipal: UserRole
Annotations:
ConstructorBinding: Microsoft.EntityFrameworkCore.Metadata.ConstructorBinding
Relational:TableName: tbl_User_UserRole
Annotations:
ProductVersion: 3.1.4
Relational:MaxIdentifierLength: 128
SqlServer:ValueGenerationStrategy: IdentityColumn
C#
var query = from userRole in UserRoles
join role in Roles on userRole.RoleId equals role.Id
where userRole.UserId.Equals(userId)
select role.Name;
Both userRole.RoleId & role.Id properties are explicitly ignored in IdentityContext.cs file. Hence EF could not translate join to the server.
@smitpatel How should it be fixed? Role tables are supported in box, without customization, so what's different here?
The properties and tables which are in the box are being used in the query. Either those mapping should not be changed by customization or if user decides to customize to remove those properties, then the query should also be updated to use the alternate properties added for those. Exact solution would depend highly upon what is the purpose of the customization being done here.
@LastImmort Can you explain the purpose of your customizations here so @smitpatel can guide you?
@blowdart @smitpatel . The purpose was mapping of identity models to existing db first schema as fast as possible and property based solution was good for that purpose. As it now clear that ignoring properties does not work any more, I've went through my projects and refactored them, I've removed all legacy custom properties and mapped native identity properties to the necessary columns. Problem is solved. Thanks to all
I am also facing similar issue with TwoFactorEnabled is set truefor user and access below method.
var result = await _signInManager.PasswordSignInAsync(user: user, password: model.Password,isPersistent : false, lockoutOnFailure: false);
It throws Object reference not set to an instance of an object.
Here is stacktrace.
at Microsoft.EntityFrameworkCore.Internal.EntityFinder`1.FindTracked(Object[] keyValues, IReadOnlyList`1& keyProperties)
at Microsoft.EntityFrameworkCore.Internal.EntityFinder`1.FindAsync(Object[] keyValues, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.FindAsync(Object[] keyValues, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`9.FindTokenAsync(TUser user, String loginProvider, String name, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Identity.UserStoreBase`5.<GetTokenAsync>d__67.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.AspNetCore.Identity.AuthenticatorTokenProvider`1.<CanGenerateTwoFactorTokenAsync>d__0.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Microsoft.AspNetCore.Identity.UserManager`1.<GetValidTwoFactorProvidersAsync>d__133.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.AspNetCore.Identity.SignInManager`1.<IsTfaEnabled>d__58.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.AspNetCore.Identity.SignInManager`1.<CheckPasswordSignInAsync>d__40.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.AspNetCore.Identity.SignInManager`1.<PasswordSignInAsync>d__38.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at AuthServer.Controllers.AccountController.<Login>d__8.MoveNext() in C:\project\identityserver\AuthServer\Controllers\AccountController.cs:line 111
@truptijogi7 - Please file a new issue on https://github.com/dotnet/efcore issue tracker.