NickStrupat / EntityFramework.Triggers

Adds events for entity inserting, inserted, updating, updated, deleting, and deleted
MIT License
373 stars 46 forks source link

The inherited properties are not saved in EF Core #26

Closed mytrash closed 6 years ago

mytrash commented 6 years ago

Hello,

I created the example project. When I make new migration: dotnet ef migration new Initialize

Could you help me where the problem is? Thank you Myth.

    public abstract class Trackable
    {
        public DateTime InsertedAt { get; private set; }
        public DateTime UpdatedAt { get; private set; }

        static Trackable()
        {
            Triggers<Trackable>.Inserting += (entry) => { entry.Entity.InsertedAt = entry.Entity.UpdatedAt = DateTime.UtcNow; };
            Triggers<Trackable>.Updating += (entry) => { entry.Entity.UpdatedAt = DateTime.UtcNow; };
        }
    }

    public class Question : Trackable
    {
        public long Id { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
    }

    public class ApplicationDbContext : DbContextWithTriggers
    {
        public DbSet<Question> Questions { get; set; }

        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
            : base(options)
        {
        }
    }
NickStrupat commented 6 years ago

I'm not an expert on EF migrations, but those properties both have private setters. Did you try removing private and check if the migration works?

NickStrupat commented 6 years ago

Any update? Did that work?