Browse Source

Merge pull request #14491 from abpframework/NotMappedAttribute

Ignore properties with `NotMappedAttribute`.
pull/14495/head
liangshiwei 4 years ago
committed by GitHub
parent
commit
1746ea73fb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs
  2. 4
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Person.cs
  3. 3
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/DateTimeKind_Tests.cs

16
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs

@ -624,21 +624,17 @@ public abstract class AbpDbContext<TDbContext> : DbContext, IAbpEfCoreDbContext,
var dateTimeValueConverter = new AbpDateTimeValueConverter(Clock); var dateTimeValueConverter = new AbpDateTimeValueConverter(Clock);
var dateTimePropertyInfos = typeof(TEntity).GetProperties() foreach (var property in mutableEntityType.GetProperties().
.Where(property => Where(property => property.PropertyInfo != null &&
(property.PropertyType == typeof(DateTime) || (property.PropertyInfo.PropertyType == typeof(DateTime) || property.PropertyInfo.PropertyType == typeof(DateTime?)) &&
property.PropertyType == typeof(DateTime?)) && property.PropertyInfo.CanWrite &&
property.CanWrite && ReflectionHelper.GetSingleAttributeOfMemberOrDeclaringTypeOrDefault<DisableDateTimeNormalizationAttribute>(property.PropertyInfo) == null))
ReflectionHelper.GetSingleAttributeOfMemberOrDeclaringTypeOrDefault<DisableDateTimeNormalizationAttribute>(property) == null
).ToList();
dateTimePropertyInfos.ForEach(property =>
{ {
modelBuilder modelBuilder
.Entity<TEntity>() .Entity<TEntity>()
.Property(property.Name) .Property(property.Name)
.HasConversion(dateTimeValueConverter); .HasConversion(dateTimeValueConverter);
}); }
} }
} }

4
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Person.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations.Schema;
using Volo.Abp.Domain.Entities.Auditing; using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
using Volo.Abp.Timing; using Volo.Abp.Timing;
@ -21,6 +22,9 @@ public class Person : FullAuditedAggregateRoot<Guid>, IMultiTenant
[DisableDateTimeNormalization] [DisableDateTimeNormalization]
public virtual DateTime? LastActive { get; set; } public virtual DateTime? LastActive { get; set; }
[NotMapped]
public virtual DateTime? NotMappedDateTime { get; set; }
public virtual Collection<Phone> Phones { get; set; } public virtual Collection<Phone> Phones { get; set; }
public virtual DateTime LastActiveTime { get; set; } public virtual DateTime LastActiveTime { get; set; }

3
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/DateTimeKind_Tests.cs

@ -41,5 +41,8 @@ public abstract class DateTimeKind_Tests<TStartupModule> : TestAppTestBase<TStar
person.LastActive.ShouldNotBeNull(); person.LastActive.ShouldNotBeNull();
person.LastActive.Value.Kind.ShouldBe(DateTimeKind.Unspecified); person.LastActive.Value.Kind.ShouldBe(DateTimeKind.Unspecified);
person.LastActive.Value.ToString("yyy-MM-dd HH:mm:ss").ShouldBe("2020-01-01 00:00:00"); person.LastActive.Value.ToString("yyy-MM-dd HH:mm:ss").ShouldBe("2020-01-01 00:00:00");
//NotMappedDateTime [NotMappedAttribute]
person.NotMappedDateTime.ShouldBeNull();
} }
} }

Loading…
Cancel
Save