Variable error in identity

0

Good afternoon guys, I'm supporting a project of my company, which is using identity config.

In this I added a deleted call variable in my database and gave an update-database and updated the database with this new variable, but when I start on my system it displays the following message.

The 'Excluido' property on 'ApplicationUser' could not be set to a 'null' value. You must set this property to a non-null value of type 'System.Boolean'.

below this my identity

using System;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using System.Data.Entity;
using System.Security.Claims;
using System.Threading.Tasks;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;

namespace IdentitySample.Models
{
    // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
    public class ApplicationUser : IdentityUser
    {
        public string Nome { get; set; }
        public string Cpf { get; set; }
        public Guid RegiaoId { get; set; }
        public bool Excluido { get; set; }
        public string Observacoes { get; set; }

        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
            // Add custom user claims here
            return userIdentity;
        }

        private ApplicationDbContext db = new ApplicationDbContext();
        public async Task<bool> GetByCpfAsync(string cpf)
        {
            var users = db.Users.Where(x => x.Cpf == cpf);
            return await users.AnyAsync();
        }

        public async Task<bool> GetByCpfAsync(string cpf, string id)
        {
            var users = db.Users.Where(x => x.Cpf == cpf && x.Id != id);
            return await users.AnyAsync();
        }
    }

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("DefaultConnection", throwIfV1Schema: false)
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
            modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();

            modelBuilder.Entity<IdentityUser>()
                .ToTable("jud_Users");

            modelBuilder.Entity<ApplicationUser>()
                .ToTable("jud_Users");


            modelBuilder.Entity<IdentityUserRole>()
                .ToTable("jud_UserRoles");

            modelBuilder.Entity<IdentityUserLogin>()
                .ToTable("jud_Logins");

            modelBuilder.Entity<IdentityUserClaim>()
                .ToTable("jud_Claims");

            modelBuilder.Entity<IdentityRole>()
                .ToTable("jud_Roles");
        }

        static ApplicationDbContext()
        {
            // Set the database intializer which is run once during application start
            // This seeds the database with admin user credentials and admin role
            Database.SetInitializer<ApplicationDbContext>(new ApplicationDbInitializer());
        }

        public static ApplicationDbContext Create()
        {
            return new ApplicationDbContext();
        }
    }
}

Could anyone help me?

    
asked by anonymous 09.10.2017 / 21:37

1 answer

0

From the error message it seems to me that you have not set the value of this new column in the existing records in the database. The framework is probably trying to "hydrate" the entity, but the Excluded property does not accept nulls. Try an "UPDATE TABLE SET Excluded = 0" in the database, or change the type of that bucket to "bool?".

    
09.10.2017 / 21:45