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 1f55bce770..13314a2b71 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs @@ -624,21 +624,17 @@ public abstract class AbpDbContext : DbContext, IAbpEfCoreDbContext, var dateTimeValueConverter = new AbpDateTimeValueConverter(Clock); - var dateTimePropertyInfos = typeof(TEntity).GetProperties() - .Where(property => - (property.PropertyType == typeof(DateTime) || - property.PropertyType == typeof(DateTime?)) && - property.CanWrite && - ReflectionHelper.GetSingleAttributeOfMemberOrDeclaringTypeOrDefault(property) == null - ).ToList(); - - dateTimePropertyInfos.ForEach(property => + foreach (var property in mutableEntityType.GetProperties(). + Where(property => property.PropertyInfo != null && + (property.PropertyInfo.PropertyType == typeof(DateTime) || property.PropertyInfo.PropertyType == typeof(DateTime?)) && + property.PropertyInfo.CanWrite && + ReflectionHelper.GetSingleAttributeOfMemberOrDeclaringTypeOrDefault(property.PropertyInfo) == null)) { modelBuilder .Entity() .Property(property.Name) .HasConversion(dateTimeValueConverter); - }); + } } } 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 f3bd13f1b4..0fc98a2a8b 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 @@ -1,5 +1,6 @@ using System; using System.Collections.ObjectModel; +using System.ComponentModel.DataAnnotations.Schema; using Volo.Abp.Domain.Entities.Auditing; using Volo.Abp.MultiTenancy; using Volo.Abp.Timing; @@ -21,6 +22,9 @@ public class Person : FullAuditedAggregateRoot, IMultiTenant [DisableDateTimeNormalization] public virtual DateTime? LastActive { get; set; } + [NotMapped] + public virtual DateTime? NotMappedDateTime { get; set; } + public virtual Collection Phones { get; set; } public virtual DateTime LastActiveTime { get; set; } diff --git a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/DateTimeKind_Tests.cs b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/DateTimeKind_Tests.cs index 502306a1b1..43489feda8 100644 --- a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/DateTimeKind_Tests.cs +++ b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/DateTimeKind_Tests.cs @@ -41,5 +41,8 @@ public abstract class DateTimeKind_Tests : TestAppTestBase