Page 1 of 1

BaseEnitity - how to do this in EntityDeveloper

Posted: Mon 17 May 2021 19:17
by Adaƛ
Hi,

my code looks like this:

Code: Select all

    public class BaseEntity
    {
        public int Id { get; set; }
        public DateTime CreatedDate { get; set; }
        public DateTime ModifiedDate { get; set; }
        public bool IsActive { get; set; }
        public bool IsDeleted { get; set; }
    }

Code: Select all

    public class Customer : BaseEntity
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }
and mappings

Code: Select all

    public class CustomerMap : IEntityTypeConfiguration<Customer>
    {
        public void Configure(EntityTypeBuilder<Customer> builder)
        {
            builder.HasKey(x => x.Id).HasName("pk_customerid");
            builder.Property(x => x.Id).ValueGeneratedOnAdd().HasColumnName("id");

            builder.Property(x => x.FirstName).HasColumnType("varchar(50)");
            builder.Property(x => x.LastName).HasColumnType("varchar(50)");



            builder.Property(x => x.CreatedDate)
                .HasColumnName("created_date")
                .HasColumnType("datetime");

            builder.Property(x => x.ModifiedDate)
                .HasColumnName("modified_date")
                .HasColumnType("datetime");

            builder.Property(x => x.IsActive)
                .HasColumnName("is_active")
                .HasColumnType("bit")
                .HasDefaultValue(1);

            builder.Property(x => x.IsDeleted)
                .HasColumnName("is_deleted")
                .HasColumnType("bit")
                .HasDefaultValue(0);
        }
    }
How can i do the same in entity developer? I can set BaseType to BaseEntity but when i generate code there is no mapping for properties from BaseEntity class.

Re: BaseEnitity - how to do this in EntityDeveloper

Posted: Tue 18 May 2021 13:54
by Shalex
Be aware that EF Core supports only TPH and TPT inheritances. TPC is not yet supported by EF Core.

Refer to https://www.devart.com/entitydeveloper/ ... s-efc.html.