private static void FillFieldsSql(DataTable chainRoot, DataTable master, DataTable current, TableType tableType, SqlDefinition exp, StringBuilder sql, TempIndex index) { if (!ContainsTable(chainRoot, exp, current)) { return; } var chain = current.GetChainCode(chainRoot); sql.AppendLine(); foreach (var field in current.Fields) { if (field.IsAdditional) { continue; //不输出附加字段,有这类需求请自行编码sql语句,因为附加字段的定制化需求统一由数据映射器处理 } if (field.Tip.Lazy && !exp.SpecifiedField(field.Name)) { continue; } if (tableType == TableType.Derived) { if (field.Name == EntityObject.IdPropertyName || field.Name == GeneratedField.RootIdName) { continue; } } var fieldName = string.Format("{0}_{1}", chain, field.Name); if (!ContainsField(fieldName, exp)) { continue; } sql.AppendFormat("{0}.{1} as {2},", SqlStatement.Qualifier(chain), SqlStatement.Qualifier(field.Name), SqlStatement.Qualifier(fieldName)); } if (current.IsEnabledMultiTenancy) { if (tableType != TableType.Derived) { var fieldName = string.Format("{0}_{1}", chain, GeneratedField.TenantIdName); sql.AppendFormat("{0}.{1} as {2},", SqlStatement.Qualifier(chain), SqlStatement.Qualifier(GeneratedField.TenantIdName), fieldName); } } FillChildSelectFieldsSql(chainRoot, current, exp, sql, index); }
private static void FillChainRootSelectFieldsSql(DataTable current, TableType tableType, SqlDefinition exp, StringBuilder sql) { sql.AppendLine(); foreach (var field in current.Fields) { if (field.IsAdditional) { continue; //不输出附加字段,有这类需求请自行编码sql语句,因为附加字段的定制化需求统一由数据映射器处理 } if (field.Tip.Lazy && !exp.SpecifiedField(field.Name)) { continue; } if (tableType == TableType.Derived) { //派生表不输出主键信息 if (field.Name == EntityObject.IdPropertyName) { continue; } if (current.Type != DataTableType.AggregateRoot) { if (field.Name == GeneratedField.RootIdName) { continue; } } } if (!ContainsField(field.Name, exp)) { continue; } sql.AppendFormat("{0}.{1} as {1},", SqlStatement.Qualifier(current.Name), SqlStatement.Qualifier(field.Name)); } if (current.IsEnabledMultiTenancy) { if (tableType != TableType.Derived) { sql.AppendFormat("{0}.{1} as {1},", SqlStatement.Qualifier(current.Name), SqlStatement.Qualifier(GeneratedField.TenantIdName)); } } }