How can i bind same column in DbModelBuilder for IdentityUser's two different properties

24 Views Asked by At

This is my table

SELECT TOP (1000) [Id]
      ,[Adi]
      ,[SoyAdi]
      ,[Maili]
      ,[Sifresi]
      ,[Adresi]
      ,[Telefonu]
      ,[KurumAdi]
      ,[VergiNo]
      ,[VergiDairesi]
      ,[TCKno]
      ,[IsActive]
      ,[IsAdmin]
      ,[IsAjans]
      ,[OlusturmaTarihi]
      ,[DuzenlemeTarihi]
      ,[KimDuzenledi]
      ,[Departman_Id]
      ,[Il_Id]
      ,[Ilce_Id]
      ,[Kategori_Id]
      ,[Onaylanmadi]
      ,[IsFreelancer]
      ,[Meslek]
      ,[UzmanOlduguKategoriler]
  FROM [AkuzelVT].[dbo].[Kullanicilar]

I have to use Entity Framework 4.8 with ASP.NET MVC 5 standard individual login with owin UserManager, SigInManager, IdentityUser etc.

I modified the ApplicationDbContext like this

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

    modelBuilder.Entity<IdentityUser>().ToTable("Kullanicilar");
    modelBuilder.Entity<IdentityUser>().Property(p => p.Id).HasColumnName("Id");
    modelBuilder.Entity<IdentityUser>().Property(p => p.Email).HasColumnName("Maili");
    modelBuilder.Entity<IdentityUser>().ToTable("Kullanicilar").Ignore(p => p.EmailConfirmed);
    modelBuilder.Entity<IdentityUser>().ToTable("Kullanicilar").Property(p => p.PasswordHash).HasColumnName("Sifresi");
    modelBuilder.Entity<IdentityUser>().ToTable("Kullanicilar").Ignore(p => p.SecurityStamp);
    modelBuilder.Entity<IdentityUser>().ToTable("Kullanicilar").Property(p => p.PhoneNumber).HasColumnName("Telefonu");
    modelBuilder.Entity<IdentityUser>().ToTable("Kullanicilar").Ignore(p => p.PhoneNumberConfirmed);
    modelBuilder.Entity<IdentityUser>().ToTable("Kullanicilar").Ignore(p => p.TwoFactorEnabled);
    modelBuilder.Entity<IdentityUser>().ToTable("Kullanicilar").Ignore(p => p.LockoutEndDateUtc);
    modelBuilder.Entity<IdentityUser>().ToTable("Kullanicilar").Ignore(p => p.LockoutEnabled);
    modelBuilder.Entity<IdentityUser>().ToTable("Kullanicilar").Ignore(p => p.AccessFailedCount);
    modelBuilder.Entity<IdentityUser>().ToTable("Kullanicilar").Property(p => p.UserName). HasColumnName("Adi");

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

    modelBuilder.Entity<ApplicationUser>().ToTable("Kullanicilar").Property(p => p.Id).HasColumnName("Id");
    modelBuilder.Entity<ApplicationUser>().ToTable("Kullanicilar").Property(p => p.Email).HasColumnName("Maili");
    modelBuilder.Entity<ApplicationUser>().ToTable("Kullanicilar").Property(p => p.PasswordHash).HasColumnName("Sifresi");
    modelBuilder.Entity<ApplicationUser>().ToTable("Kullanicilar").Property(p => p.PhoneNumber).HasColumnName("Telefonu");
    modelBuilder.Entity<ApplicationUser>().ToTable("Kullanicilar").Property(p => p.UserName).HasColumnName("Adi");
}

When I log in, I get this error page:

enter image description here

System.Data.SqlClient.SqlException: Invalid column name 'Discriminator'

When I change my code of modification like this

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

            modelBuilder.Entity<IdentityUser>().ToTable("Kullanicilar");
            modelBuilder.Entity<IdentityUser>().Property(p => p.Id).HasColumnName("Id");
            modelBuilder.Entity<IdentityUser>().Property(p => p.Email).HasColumnName("Maili");
            modelBuilder.Entity<IdentityUser>().ToTable("Kullanicilar").Ignore(p => p.EmailConfirmed);
            modelBuilder.Entity<IdentityUser>().ToTable("Kullanicilar").Property(p => p.PasswordHash).HasColumnName("Sifresi");
            modelBuilder.Entity<IdentityUser>().ToTable("Kullanicilar").Ignore(p => p.SecurityStamp);
            modelBuilder.Entity<IdentityUser>().ToTable("Kullanicilar").Property(p => p.PhoneNumber).HasColumnName("Telefonu");
            modelBuilder.Entity<IdentityUser>().ToTable("Kullanicilar").Ignore(p => p.PhoneNumberConfirmed);
            modelBuilder.Entity<IdentityUser>().ToTable("Kullanicilar").Ignore(p => p.TwoFactorEnabled);
            modelBuilder.Entity<IdentityUser>().ToTable("Kullanicilar").Ignore(p => p.LockoutEndDateUtc);
            modelBuilder.Entity<IdentityUser>().ToTable("Kullanicilar").Ignore(p => p.LockoutEnabled);
            modelBuilder.Entity<IdentityUser>().ToTable("Kullanicilar").Ignore(p => p.AccessFailedCount);
            modelBuilder.Entity<IdentityUser>().ToTable("Kullanicilar").Property(p => p.UserName). HasColumnName("Maili");

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

            modelBuilder.Entity<ApplicationUser>().ToTable("Kullanicilar").Property(p => p.Id).HasColumnName("Id");
            modelBuilder.Entity<ApplicationUser>().ToTable("Kullanicilar").Property(p => p.Email).HasColumnName("Maili");
            modelBuilder.Entity<ApplicationUser>().ToTable("Kullanicilar").Property(p => p.PasswordHash).HasColumnName("Sifresi");
            modelBuilder.Entity<ApplicationUser>().ToTable("Kullanicilar").Property(p => p.PhoneNumber).HasColumnName("Telefonu");
            modelBuilder.Entity<ApplicationUser>().ToTable("Kullanicilar").Property(p => p.UserName).HasColumnName("Maili");
}

Actually it has to be like this - then I get this error:

enter image description here

Maili: Name: Each property name in a type must be unique. Property name 'Maili' is already defined.

Can anyone help me?

0

There are 0 best solutions below