diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs index 4b3fcd1d0d..03a22f5718 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs @@ -372,7 +372,7 @@ namespace Volo.Abp.EntityFrameworkCore protected virtual void ApplyAbpConceptsForModifiedEntity(EntityEntry entry, EntityChangeReport changeReport) { - if (entry.Properties.Any(x => x.IsModified && x.Metadata.ValueGenerated == ValueGenerated.Never)) + if (entry.State == EntityState.Modified && entry.Properties.Any(x => x.IsModified && x.Metadata.ValueGenerated == ValueGenerated.Never)) { UpdateConcurrencyStamp(entry); SetModificationAuditProperties(entry); diff --git a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/TestMigrationsDbContext.cs b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/TestMigrationsDbContext.cs index 23137f0f0c..516c7d5789 100644 --- a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/TestMigrationsDbContext.cs +++ b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/TestMigrationsDbContext.cs @@ -1,3 +1,4 @@ +using System; using Microsoft.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.TestApp.SecondContext; using Volo.Abp.EntityFrameworkCore.TestApp.ThirdDbContext; @@ -16,10 +17,10 @@ namespace Volo.Abp.EntityFrameworkCore public DbSet Books { get; set; } public DbSet EntityWithIntPks { get; set; } - + public DbSet Author { get; set; } - - public TestMigrationsDbContext(DbContextOptions options) + + public TestMigrationsDbContext(DbContextOptions options) : base(options) { @@ -36,6 +37,12 @@ namespace Volo.Abp.EntityFrameworkCore b.HasKey(p => new { p.PersonId, p.Number }); }); + + modelBuilder.Entity(b => + { + b.Property(x => x.LastActiveTime).ValueGeneratedOnAddOrUpdate().HasDefaultValue(DateTime.Now); + }); + modelBuilder.Entity(b => { b.OwnsMany(c => c.Districts, d => diff --git a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/TestAppDbContext.cs b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/TestAppDbContext.cs index 9022a1efc4..6bc581ca7d 100644 --- a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/TestAppDbContext.cs +++ b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/TestAppDbContext.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +using System; +using Microsoft.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.TestApp.ThirdDbContext; using Volo.Abp.TestApp.Domain; @@ -16,10 +17,10 @@ namespace Volo.Abp.TestApp.EntityFrameworkCore public DbSet DummyEntities { get; set; } public DbSet EntityWithIntPks { get; set; } - + public DbSet Author { get; set; } - public TestAppDbContext(DbContextOptions options) + public TestAppDbContext(DbContextOptions options) : base(options) { @@ -38,7 +39,7 @@ namespace Volo.Abp.TestApp.EntityFrameworkCore modelBuilder.Entity(b => { - b.Property(x => x.LastActiveTime).ValueGeneratedOnAddOrUpdate(); + b.Property(x => x.LastActiveTime).ValueGeneratedOnAddOrUpdate().HasDefaultValue(DateTime.Now); }); modelBuilder diff --git a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Person.cs b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Person.cs index 0c17d7b250..f88e617072 100644 --- a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Person.cs +++ b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Person.cs @@ -23,7 +23,7 @@ namespace Volo.Abp.TestApp.Domain public virtual Collection Phones { get; set; } - public virtual DateTime? LastActiveTime { get; set; } + public virtual DateTime LastActiveTime { get; set; } private Person() {