我正在使用 MiniProfiler 来分析我的 sql 命令。
我现在正在处理的一个问题是 linq 生成的重复 INSERT 语句。
我已将它们转换为SqlBulkCopy
命令,但是现在它似乎没有将其记录在 MiniProfiler 的 sql 视图中。
SqlBulkCopy 甚至会有关联的命令字符串吗?
是否可以让批量复制出现在 sql 命令列表中?
我至少可以将它计入 % sql 位吗?
我知道我可以使用MiniProfiler.Current.Step("Doing Bulk Copy")
,但这不会算作 SQL,并且不会在列表中显示任何详细信息。
当前代码如下:
public static void BulkInsertAll<T>(this DataContext dc, IEnumerable<T> entities)
{
var conn = (dc.Connection as ProfiledDbConnection).InnerConnection as SqlConnection;
conn.Open();
Type t = typeof(T);
var tableAttribute = (TableAttribute)t.GetCustomAttributes(
typeof(TableAttribute), false).Single();
var bulkCopy = new SqlBulkCopy(conn)
{
DestinationTableName = tableAttribute.Name
};
//....
bulkCopy.WriteToServer(table);
}