maliming
4 years ago
No known key found for this signature in database
GPG Key ID: 96224957E51C89E
3 changed files with
13 additions and
10 deletions
-
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs
-
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Person.cs
-
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/DateTimeKind_Tests.cs
|
|
|
@ -624,21 +624,17 @@ public abstract class AbpDbContext<TDbContext> : 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<DisableDateTimeNormalizationAttribute>(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<DisableDateTimeNormalizationAttribute>(property.PropertyInfo) == null)) |
|
|
|
{ |
|
|
|
modelBuilder |
|
|
|
.Entity<TEntity>() |
|
|
|
.Property(property.Name) |
|
|
|
.HasConversion(dateTimeValueConverter); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -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<Guid>, IMultiTenant |
|
|
|
[DisableDateTimeNormalization] |
|
|
|
public virtual DateTime? LastActive { get; set; } |
|
|
|
|
|
|
|
[NotMapped] |
|
|
|
public virtual DateTime? NotMappedDateTime { get; set; } |
|
|
|
|
|
|
|
public virtual Collection<Phone> Phones { get; set; } |
|
|
|
|
|
|
|
public virtual DateTime LastActiveTime { get; set; } |
|
|
|
|
|
|
|
@ -41,5 +41,8 @@ public abstract class DateTimeKind_Tests<TStartupModule> : TestAppTestBase<TStar |
|
|
|
person.LastActive.ShouldNotBeNull(); |
|
|
|
person.LastActive.Value.Kind.ShouldBe(DateTimeKind.Unspecified); |
|
|
|
person.LastActive.Value.ToString("yyy-MM-dd HH:mm:ss").ShouldBe("2020-01-01 00:00:00"); |
|
|
|
|
|
|
|
//NotMappedDateTime [NotMappedAttribute]
|
|
|
|
person.NotMappedDateTime.ShouldBeNull(); |
|
|
|
} |
|
|
|
} |
|
|
|
|