The only problem i have now that i finished my database design is that the AUTO_INCREMENT is not specified when creating the tables by EF Core.
This is the modelBuilder
modelBuilder.Entity<Conturi>(entity =>
{
entity.ToTable("conturi");
entity.HasKey(e => e.IdCont);
entity.Property(e => e.IdCont)
.HasColumnName("id_cont")
.HasColumnType("integer")
.ValueGeneratedOnAdd();
entity.Property(e => e.Nume)
.HasMaxLength(10)
.HasColumnName("nume")
.HasColumnType("varchar");
entity.Property(e => e.Prenume)
.HasMaxLength(20)
.HasColumnName("prenume")
.HasColumnType("varchar");
entity.Property(e => e.Gen)
.HasColumnName("gen")
.HasColumnType("tinyint");
entity.Property(e => e.NrTelefon)
.HasColumnName("nr_telefon")
.HasColumnType("varchar")
.HasMaxLength(10);
entity.Property(e => e.Username)
.HasColumnName("username")
.HasColumnType("varchar")
.HasMaxLength(15)
.IsRequired();
entity.Property(e => e.Email)
.HasColumnName("email")
.HasColumnType("varchar")
.HasMaxLength(50)
.IsRequired();
entity.Property(e => e.Parola)
.HasColumnName("parola")
.HasColumnType("varchar")
.HasMaxLength(150)
.IsRequired();
entity.Property(e => e.DataCreare)
.HasColumnName("data_creare")
.HasColumnType("datetime")
.HasDefaultValueSql("NOW()");
entity.Property(e => e.CodActivare)
.HasColumnName("cod_activare")
.HasColumnType("varchar")
.HasMaxLength(100)
.IsRequired();
entity.Property(e => e.Verificat)
.HasColumnName("verificat")
.HasColumnType("tinyint")
.IsRequired();
entity.Property(e => e.Rol)
.HasColumnName("rol")
.HasColumnType("varchar")
.HasMaxLength(15)
.IsRequired();
entity.HasMany(e => e.AdreseConturi)
.WithOne(e => e.Cont)
.HasForeignKey(e => e.IdCont)
.IsRequired();
});
This is the entity model :
public class Conturi : ICloneable
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int IdCont { get; init; } //
[StringLength(10)]
public string? Nume { get; init; } //
[StringLength(20)]
public string? Prenume { get; init; } //
public bool? Gen { get; init; } //
[StringLength(10)]
public string? NrTelefon { get; init; } //
[StringLength(15)]
public string Username { get; init; } //
[StringLength(50)]
public string Email { get; init; }
[StringLength(150)]
public string Parola { get; init; }
public DateTime? DataCreare { get; init; }
[StringLength(100)]
public string CodActivare { get; set; }
public bool Verificat { get; set; }
[StringLength(15)]
public string Rol { get; init; }
public ICollection<Adrese>? AdreseConturi { get;}
public Conturi()
{
}
public Conturi(string? nume, string? prenume, bool? gen, string? nrTelefon, string username,
string email, string parola, DateTime? dataCreare,
string codActivare, bool verificat, string rol , ICollection<Adrese>? adreseConturi)
{
Nume = nume;
Prenume = prenume;
Gen = gen;
NrTelefon = nrTelefon;
Username = username;
Email = email;
Parola = parola;
DataCreare = dataCreare;
CodActivare = codActivare;
Verificat = verificat;
Rol = rol;
AdreseConturi = adreseConturi == null ? new HashSet<Adrese>() : new HashSet<Adrese>(adreseConturi);
}
// Copy Constructor
public Conturi(Conturi other)
{
ArgumentNullException.ThrowIfNull(other);
IdCont = other.IdCont;
Nume = other.Nume;
Prenume = other.Prenume;
Gen = other.Gen;
NrTelefon = other.NrTelefon;
Username = other.Username;
Email = other.Email;
Parola = other.Parola;
DataCreare = other.DataCreare;
CodActivare = other.CodActivare;
Verificat = other.Verificat;
Rol = other.Rol;
AdreseConturi = other.AdreseConturi != null ? new HashSet<Adrese>(other.AdreseConturi) : new HashSet<Adrese>();
}
public object Clone()
{
return new Conturi(this);
}
}
I got the latest version of Pomelo , EF Core , etc.
and this is how i see it in my DataGrip after running the migrations and updating the database.
micro.png
Why it is no AUTO_INCREMENT selected there , even tho i specified in my EF Core fluent API , even in my model ?