- 增加 IInsert.ToDataTable 方法,为 BulkCopy 操作提供数据,该文件处理了(表名、字段名、类型)映射和忽略列;

This commit is contained in:
28810
2019-12-20 21:53:44 +08:00
parent ab1d0a2cb5
commit c268970c71
4 changed files with 173 additions and 0 deletions

View File

@ -464,6 +464,31 @@ namespace FreeSql.Internal.CommonProvider
_params = specialParams.ToArray();
return sb.ToString();
}
public DataTable ToDataTable()
{
var dt = new DataTable();
dt.TableName = TableRuleInvoke();
foreach (var col in _table.ColumnsByPosition)
{
if (col.Attribute.IsIdentity && _insertIdentity == false) continue;
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name)) continue;
dt.Columns.Add(col.Attribute.Name, col.Attribute.MapType);
}
foreach (var d in _source)
{
var row = new object[dt.Columns.Count];
var rowIndex = 0;
foreach (var col in _table.ColumnsByPosition)
{
if (col.Attribute.IsIdentity && _insertIdentity == false) continue;
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name)) continue;
row[rowIndex++] = col.GetMapValue(d);
}
dt.Rows.Add(row);
}
return dt;
}
}
}