Exemplo n.º 1
0
        internal static DbCompiledModel GetCompiledModel(string connectionName)
        {
            return(registeredModels.GetOrAdd(connectionName, connectionString =>
            {
                var builder = new DbModelBuilder();
                CFConfig.Default.ParallelScanAttributes <TableAttribute>((type, attr) =>
                {
                    //注册实体类型
                    typeof(DynamicContext).GetMethod("ConfigMap", BindingFlags.NonPublic | BindingFlags.Static).MakeGenericMethod(type).Invoke(null, new object[] { builder });
                    //设置TableAttribute属性
                    var config = builder.Types().Where(entity => entity == type);
                    config.Configure(entity =>
                    {
                        var entityConfig = DataEntityUtils.Entity(type);
                        entity.HasEntitySetName(entityConfig.TableAttribute.TableName);
                        entity.ToTable(entityConfig.TableAttribute.TableName);
                        entity.HasKey(entityConfig.TableAttribute.PrimaryKey);
                        foreach (var field in entityConfig.ColumnAttributes)
                        {
                            if (field.Value.IsExtend /* && !field.Value.IsInherit*/)
                            {
                                entity.Ignore(field.Key);
                            }
                        }
                    });
                });

                DbConnection connection = GetConnection(connectionString);
                DbModel model = builder.Build(connection);
                return model.Compile();
            }));
        }
Exemplo n.º 2
0
 public RepositoryBase()
 {
     this._entityDefinition = new Lazy <DataEntityDefinition>(() => DataEntityUtils.Entity(typeof(TEntity)));
     this.OnAdd            += RepositoryBase_OnAdd;
     this.OnModify         += RepositoryBase_OnModify;
     this.OnRemove         += RepositoryBase_OnRemove;
     this.OnGet            += RepositoryBase_OnGet;
 }
Exemplo n.º 3
0
 /// <summary>
 /// 注册实体配置
 /// </summary>
 /// <param name="config"></param>
 /// <returns></returns>
 public static CFConfig RegisterDataMapping(this CFConfig config)
 {
     config.ScanAttributes <TableAttribute>((type, attribute) =>
     {
         DataEntityUtils.Entity(type);
     });
     return(config);
 }
Exemplo n.º 4
0
 public Entity()
 {
     this.Property = DataEntityUtils.Entity(this.GetType()).Clone(this);
 }