mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-20 04:48:16 +08:00
- 增加 IInsert.ToDataTable 方法,为 BulkCopy 操作提供数据,该文件处理了(表名、字段名、类型)映射和忽略列;
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user