分支自 SuZhouGuanHong/TaiYuanTaiZhong

WMS
dengjunjie
2023-12-13 d772a6cddc8ed656a2cb5604fc02f6e891db546e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
 
//namespace WIDESEA_Entity.MappingConfiguration
//{
 
//    public interface IEntityMappingConfiguration
//    {
//        void Map(ModelBuilder b);
//    }
 
//    public interface IEntityMappingConfiguration<T> : IEntityMappingConfiguration where T : class
//    {
//        void Map(EntityTypeBuilder<T> builder);
//    }
 
//    public abstract class EntityMappingConfiguration<T> : IEntityMappingConfiguration<T> where T : class
//    {
//        public abstract void Map(EntityTypeBuilder<T> b);
 
//        public void Map(ModelBuilder b)
//        {
//            Map(b.Entity<T>());
//        }
//    }
 
//    public static class ModelBuilderExtenions
//    {
//        private static IEnumerable<Type> GetMappingTypes(this Assembly assembly, Type mappingInterface)
//        {
//            return assembly.GetTypes().Where(x => !x.IsAbstract && x.GetInterfaces().Any(y => y.GetTypeInfo().IsGenericType && y.GetGenericTypeDefinition() == mappingInterface));
//        }
 
//        public static void AddEntityConfigurationsFromAssembly(this ModelBuilder modelBuilder, Assembly assembly)
//        {
//            var mappingTypes = assembly.GetMappingTypes(typeof(IEntityMappingConfiguration<>));
//            foreach (var config in mappingTypes.Select(Activator.CreateInstance).Cast<IEntityMappingConfiguration>())
//            {
//                config.Map(modelBuilder);
//            }
//        }
//    }
//}