Správičky 2 815 Blogy 948 Fórum 18 732

Invalid column name 'Discriminator'.

photo
core
5. 8. 2018 3:35:09
Body: 245
Najaktívnejší č.: 57

Invalid column name 'Discriminator'.

vsetko sa zda byt ok aj tak vyhadzuje hlasku Invalid column name 'Discriminator'

pouzivam verziu 2.1.302 net core, pridal som stlpec Adresa na koniec do tabulky AspNetUsers

a nasledne som upravil

  public class MyIdentityUser : IdentityUser
    {
        public string Adresa { get; set; }                  
           }
      public class MyRole : IdentityRole
    {
               
    }

 public class ApplicationDbContext : IdentityDbContext
    {
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
            : base(options)
        {
        }
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
            builder.Entity<MyIdentityUser>().ToTable("AspNetUsers");
         
        }
        public virtual DbSet<MyIdentityUser> AspNetUsers { get; set; }
    }

v startup

            services.AddDefaultIdentity<MyIdentityUser>()
                .AddEntityFrameworkStores<ApplicationDbContext>();

public class RegisterModel : PageModel
    {
        private readonly SignInManager<MyIdentityUser> _signInManager;
        private readonly UserManager<MyIdentityUser> _userManager;
        private readonly ILogger<RegisterModel> _logger;
        private readonly IEmailSender _emailSender;

        public RegisterModel(
            UserManager<MyIdentityUser> userManager,
            SignInManager<MyIdentityUser> signInManager,
            ILogger<RegisterModel> logger,
            IEmailSender emailSender)
        {
            _userManager = userManager;
            _signInManager = signInManager;
            _logger = logger;
            _emailSender = emailSender;
        }

        [BindProperty]
        public InputModel Input { get; set; }

        public string ReturnUrl { get; set; }

        public class InputModel
        {
            [Required]
            [EmailAddress]
            [Display(Name = "Email")]
            public string Email { get; set; }
          
            [Display(Name = "Adresa")]
            public string Adresa { get; set; }
            [Required]
            [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
            [DataType(DataType.Password)]
            [Display(Name = "Password")]
            public string Password { get; set; }

            [DataType(DataType.Password)]
            [Display(Name = "Confirm password")]
            [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
            public string ConfirmPassword { get; set; }
        }

        public void OnGet(string returnUrl = null)
        {
            ReturnUrl = returnUrl;
        }

      

public class RegisterModel : PageModel
    {
        private readonly SignInManager<MyIdentityUser> _signInManager;
        private readonly UserManager<MyIdentityUser> _userManager;
        private readonly ILogger<RegisterModel> _logger;
        private readonly IEmailSender _emailSender;

        public RegisterModel(
            UserManager<MyIdentityUser> userManager,
            SignInManager<MyIdentityUser> signInManager,
            ILogger<RegisterModel> logger,
            IEmailSender emailSender)
        {
            _userManager = userManager;
            _signInManager = signInManager;
            _logger = logger;
            _emailSender = emailSender;
        }

        [BindProperty]
        public InputModel Input { get; set; }

        public string ReturnUrl { get; set; }

        public class InputModel
        {
            [Required]
            [EmailAddress]
            [Display(Name = "Email")]
            public string Email { get; set; }
          
            [Display(Name = "Adresa")]
            public string Adresa { get; set; }
            [Required]
            [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
            [DataType(DataType.Password)]
            [Display(Name = "Password")]
            public string Password { get; set; }

            [DataType(DataType.Password)]
            [Display(Name = "Confirm password")]
            [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
            public string ConfirmPassword { get; set; }
        }

        public void OnGet(string returnUrl = null)
        {
            ReturnUrl = returnUrl;
        }

        public async Task<IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                var user = new MyIdentityUser { UserName = Input.Email, Email = Input.Email,Adresa=Input.Adresa };
                var result = await _userManager.CreateAsync(user, Input.Password);
                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);



[Reakcia]

photo
core
5. 8. 2018 4:17:59
Body: 245
Najaktívnejší č.: 57

RE: Invalid column name 'Discriminator'.

problem som vyriesil takto

 protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
            builder.Entity<IdentityUser>()
             .HasDiscriminator<string>("UserName");
           builder.Entity<MyIdentityUser>().ToTable("AspNetUsers");

[Reakcia]

photo
core
6. 8. 2018 3:03:28
Body: 245
Najaktívnejší č.: 57

RE: Invalid column name 'Discriminator'.

pri tomto sposobe som narazil na problem login not work,nejde prihlasit,registracia je ok

var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: false);

 

[Reakcia]

photo
core
6. 8. 2018 3:45:48
Body: 245
Najaktívnejší č.: 57

RE: Invalid column name 'Discriminator'.

nasiel som chybu,teraz to ide

public class ApplicationDbContext : IdentityDbContext<MyIdentityUser>

 

[Reakcia]



Najaktívnejší užívatelia
1. 37775 b. photo vlko
2. 21430 b. photo T
3. 15955 b. photo spigi
4. 15450 b. photo Anonymous
5. 11120 b. photo dudok
6. 9610 b. photo Liero
7. 6910 b. photo siro
8. 6245 b. photo slavof
9. 5395 b. photo duracellko
10. 4640 b. photo xxxmatko