mirror of https://github.com/abpframework/abp.git
8 changed files with 145 additions and 78 deletions
@ -1,37 +1,41 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
using Microsoft.EntityFrameworkCore.Metadata.Builders; |
|||
|
|||
namespace Volo.Abp.ObjectExtending |
|||
{ |
|||
public static class EfCoreObjectExtensionInfoExtensions |
|||
{ |
|||
public static ObjectExtensionPropertyInfo MapEfCoreProperty<TDbField>( |
|||
this ObjectExtensionInfo objectExtensionInfo, |
|||
string propertyName, |
|||
Action<PropertyBuilder> propertyBuildAction) |
|||
public static ObjectExtensionInfo MapEfCoreProperty<TProperty>( |
|||
[NotNull] this ObjectExtensionInfo objectExtensionInfo, |
|||
[NotNull] string propertyName, |
|||
[CanBeNull] Action<PropertyBuilder> propertyBuildAction) |
|||
{ |
|||
return objectExtensionInfo.MapEfCoreProperty( |
|||
typeof(TDbField), |
|||
typeof(TProperty), |
|||
propertyName, |
|||
propertyBuildAction |
|||
); |
|||
} |
|||
|
|||
public static ObjectExtensionPropertyInfo MapEfCoreProperty( |
|||
this ObjectExtensionInfo objectExtensionInfo, |
|||
Type dbFieldType, |
|||
string propertyName, |
|||
Action<PropertyBuilder> propertyBuildAction) |
|||
public static ObjectExtensionInfo MapEfCoreProperty( |
|||
[NotNull] this ObjectExtensionInfo objectExtensionInfo, |
|||
[NotNull] Type propertyType, |
|||
[NotNull] string propertyName, |
|||
[CanBeNull] Action<PropertyBuilder> propertyBuildAction) |
|||
{ |
|||
Check.NotNull(objectExtensionInfo, nameof(objectExtensionInfo)); |
|||
|
|||
return objectExtensionInfo.AddOrUpdateProperty( |
|||
propertyType, |
|||
propertyName, |
|||
options => |
|||
{ |
|||
options.MapEfCore( |
|||
dbFieldType, |
|||
propertyBuildAction |
|||
); |
|||
}); |
|||
} |
|||
); |
|||
} |
|||
} |
|||
} |
|||
@ -1,75 +1,73 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore.Metadata.Builders; |
|||
using Volo.Abp.Data; |
|||
|
|||
namespace Volo.Abp.ObjectExtending |
|||
{ |
|||
public static class EfCoreObjectExtensionManagerExtensions |
|||
{ |
|||
public static ObjectExtensionInfo MapEfCoreProperty<TObject, TDbField>( |
|||
public static ObjectExtensionManager MapEfCoreProperty<TObject, TProperty>( |
|||
this ObjectExtensionManager objectExtensionManager, |
|||
string propertyName, |
|||
Action<PropertyBuilder> propertyBuildAction) |
|||
where TObject : IHasExtraProperties |
|||
{ |
|||
return objectExtensionManager.MapEfCoreProperty( |
|||
typeof(TObject), |
|||
typeof(TDbField), |
|||
typeof(TProperty), |
|||
propertyName, |
|||
propertyBuildAction |
|||
); |
|||
} |
|||
|
|||
public static ObjectExtensionInfo MapEfCoreProperty( |
|||
public static ObjectExtensionManager MapEfCoreProperty( |
|||
this ObjectExtensionManager objectExtensionManager, |
|||
Type objectType, |
|||
Type dbFieldType, |
|||
Type propertyType, |
|||
string propertyName, |
|||
Action<PropertyBuilder> propertyBuildAction) |
|||
{ |
|||
return objectExtensionManager.AddOrUpdate( |
|||
return objectExtensionManager.AddOrUpdateProperty( |
|||
objectType, |
|||
objectOptions => |
|||
propertyType, |
|||
propertyName, |
|||
options => |
|||
{ |
|||
objectOptions.AddOrUpdateProperty( |
|||
propertyName, |
|||
propertyOptions => |
|||
{ |
|||
propertyOptions.MapEfCore( |
|||
dbFieldType, |
|||
propertyBuildAction |
|||
); |
|||
} |
|||
options.MapEfCore( |
|||
propertyBuildAction |
|||
); |
|||
}); |
|||
} |
|||
); |
|||
} |
|||
|
|||
public static void ConfigureEfCoreEntity( |
|||
this ObjectExtensionManager objectExtensionManager, |
|||
EntityTypeBuilder b) |
|||
public static void ConfigureEfCoreEntity( |
|||
this ObjectExtensionManager objectExtensionManager, |
|||
EntityTypeBuilder b) |
|||
{ |
|||
var objectExtension = objectExtensionManager.GetOrNull(b.Metadata.ClrType); |
|||
if (objectExtension == null) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
foreach (var property in objectExtension.GetProperties()) |
|||
{ |
|||
var objectExtension = objectExtensionManager.GetOrNull(b.Metadata.ClrType); |
|||
if (objectExtension == null) |
|||
var efCoreMapping = property.GetEfCoreMappingOrNull(); |
|||
if (efCoreMapping == null) |
|||
{ |
|||
return; |
|||
continue; |
|||
} |
|||
|
|||
foreach (var property in objectExtension.GetProperties()) |
|||
/* Prevent multiple calls to the entityTypeBuilder.Property(...) method */ |
|||
if (b.Metadata.FindProperty(property.Name) != null) |
|||
{ |
|||
var efCoreMapping = property.GetEfCoreMappingOrNull(); |
|||
if (efCoreMapping == null) |
|||
{ |
|||
continue; |
|||
} |
|||
|
|||
/* Prevent multiple calls to the entityTypeBuilder.Property(...) method */ |
|||
if (b.Metadata.FindProperty(property.Name) != null) |
|||
{ |
|||
continue; |
|||
} |
|||
continue; |
|||
} |
|||
|
|||
var propertyBuilder = b.Property(efCoreMapping.FieldType, property.Name); |
|||
var propertyBuilder = b.Property(property.Type, property.Name); |
|||
|
|||
efCoreMapping.PropertyBuildAction?.Invoke(propertyBuilder); |
|||
} |
|||
efCoreMapping.PropertyBuildAction?.Invoke(propertyBuilder); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,44 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Data; |
|||
|
|||
namespace Volo.Abp.ObjectExtending |
|||
{ |
|||
public static class ObjectExtensionManagerExtensions |
|||
{ |
|||
public static ObjectExtensionManager AddOrUpdateProperty<TObject, TProperty>( |
|||
[NotNull] this ObjectExtensionManager objectExtensionManager, |
|||
[NotNull] string propertyName, |
|||
[CanBeNull] Action<ObjectExtensionPropertyInfo> configureAction = null) |
|||
where TObject : IHasExtraProperties |
|||
{ |
|||
return objectExtensionManager.AddOrUpdateProperty( |
|||
typeof(TObject), |
|||
typeof(TProperty), |
|||
propertyName, |
|||
configureAction |
|||
); |
|||
} |
|||
|
|||
public static ObjectExtensionManager AddOrUpdateProperty( |
|||
[NotNull] this ObjectExtensionManager objectExtensionManager, |
|||
[NotNull] Type objectType, |
|||
[NotNull] Type propertyType, |
|||
[NotNull] string propertyName, |
|||
[CanBeNull] Action<ObjectExtensionPropertyInfo> configureAction = null) |
|||
{ |
|||
Check.NotNull(objectExtensionManager, nameof(objectExtensionManager)); |
|||
|
|||
return objectExtensionManager.AddOrUpdate( |
|||
objectType, |
|||
options => |
|||
{ |
|||
options.AddOrUpdateProperty( |
|||
propertyType, |
|||
propertyName, |
|||
configureAction |
|||
); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue