public static void ConfigureEfCoreEntity(
            [NotNull] this ObjectExtensionManager objectExtensionManager,
            [NotNull] EntityTypeBuilder typeBuilder)
        {
            Check.NotNull(objectExtensionManager, nameof(objectExtensionManager));
            Check.NotNull(typeBuilder, nameof(typeBuilder));

            var objectExtension = objectExtensionManager.GetOrNull(typeBuilder.Metadata.ClrType);

            if (objectExtension == null)
            {
                return;
            }

            foreach (var property in objectExtension.GetProperties())
            {
                var efCoreMapping = property.GetEfCoreMappingOrNull();
                if (efCoreMapping == null)
                {
                    continue;
                }

                /* Prevent multiple calls to the entityTypeBuilder.Property(...) method */
                if (typeBuilder.Metadata.FindProperty(property.Name) != null)
                {
                    continue;
                }

                var propertyBuilder = typeBuilder.Property(property.Type, property.Name);

                efCoreMapping.PropertyBuildAction?.Invoke(propertyBuilder);
            }
        }
Esempio n. 2
0
        public static ObjectExtensionPropertyInfo GetPropertyOrNull(
            [NotNull] this ObjectExtensionManager objectExtensionManager,
            [NotNull] Type objectType,
            [NotNull] string propertyName)
        {
            Check.NotNull(objectExtensionManager, nameof(objectExtensionManager));
            Check.NotNull(objectType, nameof(objectType));
            Check.NotNull(propertyName, nameof(propertyName));

            return(objectExtensionManager
                   .GetOrNull(objectType)?
                   .GetPropertyOrNull(propertyName));
        }
Esempio n. 3
0
        public static ImmutableList <ObjectExtensionPropertyInfo> GetProperties(
            [NotNull] this ObjectExtensionManager objectExtensionManager,
            [NotNull] Type objectType)
        {
            Check.NotNull(objectExtensionManager, nameof(objectExtensionManager));
            Check.NotNull(objectType, nameof(objectType));

            var extensionInfo = objectExtensionManager.GetOrNull(objectType);

            if (extensionInfo == null)
            {
                return(EmptyPropertyList);
            }

            return(extensionInfo.GetProperties());
        }
Esempio n. 4
0
        public static void ConfigureEfCoreDbContext <TDbContext>(
            [NotNull] this ObjectExtensionManager objectExtensionManager,
            [NotNull] ModelBuilder modelBuilder)
            where TDbContext : DbContext
        {
            Check.NotNull(objectExtensionManager, nameof(objectExtensionManager));
            Check.NotNull(modelBuilder, nameof(modelBuilder));

            var objectExtension = objectExtensionManager.GetOrNull(typeof(TDbContext));

            if (objectExtension == null)
            {
                return;
            }

            var efCoreDbContextMappings = objectExtension.GetEfCoreDbContextMappings();

            foreach (var efCoreDbContextMapping in efCoreDbContextMappings)
            {
                efCoreDbContextMapping.ModelBuildAction?.Invoke(modelBuilder);
            }
        }