Asp.Net Core 3.1 LinqToDB.Identity UserManager CreateAsync Error
See original GitHub issueI have implemented LinqToDB.Identity into my project. I have been trying to create a user by using .Net Identity UserManager, but I am getting an error. I have also implemented LinqToDB.Identity optimizations, such as AddLinqToDBStores and IdentityConnectionFactory.
As I have mentioned about it, I am getting an error like this when I try to create an user.
{“Method not found: ‘Int32 LinqToDB.DataExtensions.Insert(LinqToDB.IDataContext, System.__Canon, System.String, System.String, System.String)’.”}
Here is an image that shows the error.
https://i.stack.imgur.com/8oZ98.png
Here is my AddLinqToDBStores options and configurations.
` public static void AddDevPlatformAuthentication(this IServiceCollection services, IConfiguration configuration)
{
services.AddIdentity<AppUser, LinqToDB.Identity.IdentityRole<int>>(options =>
{
options.Password.RequireDigit = true;
options.Password.RequiredLength = 4;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = true;
options.Password.RequireLowercase = false;
options.User.RequireUniqueEmail = true;
//TODO
//options.User.RequireUniqueEmail = true;
//options.SignIn.RequireConfirmedEmail = true;
//options.Lockout.MaxFailedAccessAttempts = 5;
//options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(3);
}).AddLinqToDBStores<int, AppUserClaim, AppUserRole, AppUserLogin, AppUserToken, AppRoleClaim>(new
IdentityConnectionFactory(new SqlServerDataProvider(ProviderName.SqlServer, SqlServerVersion.v2017), "SqlServerIdentity", DataSettingsManager.LoadSettings().ConnectionString))
.AddDefaultTokenProviders();
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();
// Uncomment the following lines to enable logging in with third party login providers
JwtTokenDefinitions.LoadFromConfiguration(configuration);
services.ConfigureJwtAuthentication();
services.ConfigureJwtAuthorization();
}`
Here is my IdentityConnectionFactory class that has inherited from IConnectionFactory interface.
`public class IdentityConnectionFactory : IConnectionFactory
{
private static readonly Dictionary<string, HashSet<string>> _tables = new Dictionary<string, HashSet<string>>();
private readonly string _configuration;
private readonly string _connectionString;
private readonly string _key;
private readonly IDataProvider _provider;
public IdentityConnectionFactory(IDataProvider provider, string configuration, string connectionString)
{
_provider = provider;
Configuration.Linq.AllowMultipleQuery = true;
//DataConnection.AddConfiguration(configuration, connectionString, provider);
_configuration = configuration;
_connectionString = connectionString;
_key = _configuration + "$$" + _connectionString;
}
public IDataContext GetContext()
{
return new DataContext(_provider, _connectionString);
}
public DataConnection GetConnection()
{
var db = new DataConnection(_provider, _connectionString);
db.AddMappingSchema(AdditionalSchema);
return db;
}
protected MappingSchema AdditionalSchema
{
get
{
if (!(Singleton<MappingSchema>.Instance is null))
return Singleton<MappingSchema>.Instance;
Singleton<MappingSchema>.Instance =
new MappingSchema(_provider.Name) { MetadataReader = new FluentMigratorMetadataReader() };
return Singleton<MappingSchema>.Instance;
}
}`
Here is my Register api that can be used to create an user by using UserManager.
` public async Task<JsonResult> Register([FromBody] RegisterApiRequest model)
{
try
{
if (model.RePassword != model.Password)
{
return BadResponse(ResultModel.Error("Repassword must match password"));
}
AppUser userEntity = new AppUser
{
UserName = model.UserName,
Email = model.Email,
CreatedDate = DateTime.Now,
DetailId = 1
};
IdentityResult result = await _userManager.CreateAsync(userEntity, model.Password);
if (!result.Succeeded)
{
Result.Status = false;
Result.Message = string.Join(",", result.Errors.Select(x => x.Description));
return BadResponse(Result);
}
return OkResponse(Result);
}
catch (Exception ex)
{
Result.Status = false;
Result.Message = ex.ToString();
return BadResponse(Result);
}
}`
There are so many code blocks that I can not paste here. I would be very happy if someone could help.
If you would like to see the project, you can check here;
https://github.com/dogaanismail/DevPlatform
I have asked this question on Stackoverflow. Here is the link.
Any help would be appreciated!
Environment details
linq2db version: v3.0.1 Database Server: Microsoft Sql Server Database Provider: SqlServerDataProvider Operating system: Windows 10 .NET Framework: .Net Core 3.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
I see some mix of EF and linq2db. DatabaseGenerated(DatabaseGeneratedOption.Identity) is not linq2db attribute. Try to use [Identity] attribute instead. Sorry it’s to late here and I’m just giving ideas without trying them. Method not found exception means that some reflection code is used in exception path, that’s why I’ve mentioned that I have not found anything “criminal” in code.
Sure, you can close the issue. Thanks a lot for your help.
Best Regards