private void InitMppingInfo(EntityInfo entityInfo) { if (this.Context.MappingTables == null) { this.Context.MappingTables = new MappingTableList(); } if (this.Context.MappingColumns == null) { this.Context.MappingColumns = new MappingColumnList(); } if (this.Context.IgnoreColumns == null) { this.Context.IgnoreColumns = new IgnoreColumnList(); } if (this.Context.IgnoreInsertColumns == null) { this.Context.IgnoreInsertColumns = new IgnoreColumnList(); } if (!this.Context.MappingTables.Any(it => it.EntityName == entityInfo.EntityName)) { if (entityInfo.DbTableName != entityInfo.EntityName && entityInfo.DbTableName.HasValue()) { this.Context.MappingTables.Add(entityInfo.EntityName, entityInfo.DbTableName); } } if (entityInfo.Columns.Any(it => it.EntityName == entityInfo.EntityName)) { var mappingColumnInfos = this.Context.MappingColumns.Where(it => it.EntityName == entityInfo.EntityName); foreach (var item in entityInfo.Columns.Where(it => it.IsIgnore == false)) { if (!mappingColumnInfos.Any(it => it.PropertyName == item.PropertyName)) { if (item.PropertyName != item.DbColumnName && item.DbColumnName.HasValue()) { this.Context.MappingColumns.Add(item.PropertyName, item.DbColumnName, item.EntityName); } } } var ignoreInfos = this.Context.IgnoreColumns.Where(it => it.EntityName == entityInfo.EntityName); foreach (var item in entityInfo.Columns.Where(it => it.IsIgnore)) { if (!ignoreInfos.Any(it => it.PropertyName == item.PropertyName)) { this.Context.IgnoreColumns.Add(item.PropertyName, item.EntityName); } } var ignoreInsertInfos = this.Context.IgnoreInsertColumns.Where(it => it.EntityName == entityInfo.EntityName); foreach (var item in entityInfo.Columns.Where(it => it.IsOnlyIgnoreInsert)) { if (!ignoreInsertInfos.Any(it => it.PropertyName == item.PropertyName)) { this.Context.IgnoreInsertColumns.Add(item.PropertyName, item.EntityName); } } } }
private string GetDbColumnName(string entityName) { if (!IsMappingColumns) { return(entityName); } if (this.Context.MappingColumns.Any(it => it.EntityName.Equals(EntityInfo.EntityName, StringComparison.CurrentCultureIgnoreCase))) { this.MappingColumnList = this.Context.MappingColumns.Where(it => it.EntityName.Equals(EntityInfo.EntityName, StringComparison.CurrentCultureIgnoreCase)).ToList(); } if (MappingColumnList == null || !MappingColumnList.Any()) { return(entityName); } else { var mappInfo = this.Context.MappingColumns.FirstOrDefault(it => it.PropertyName.Equals(entityName, StringComparison.CurrentCultureIgnoreCase)); return(mappInfo == null ? entityName : mappInfo.DbColumnName); } }