Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 让SqlBulkCopy在MiniProfiler中显示为sql_C#_Sqlbulkcopy_Mvc Mini Profiler - Fatal编程技术网

C# 让SqlBulkCopy在MiniProfiler中显示为sql

C# 让SqlBulkCopy在MiniProfiler中显示为sql,c#,sqlbulkcopy,mvc-mini-profiler,C#,Sqlbulkcopy,Mvc Mini Profiler,我正在使用MiniProfiler分析我的sql命令 我现在要处理的一个问题是linq生成的重复INSERT语句 我已经将它们转换为SqlBulkCopy命令,但是现在它似乎没有在MiniProfiler的sql视图中记录它 SqlBulkCopy是否会有关联的命令字符串 是否可以将大容量副本显示在sql命令列表中 我至少可以将其计入%sql位吗 我知道我可以使用MiniProfiler.Current.Step(“执行大容量复制”),但这不算作SQL,也不会在清单中显示任何细节 当前代码如

我正在使用MiniProfiler分析我的sql命令

我现在要处理的一个问题是linq生成的重复INSERT语句

我已经将它们转换为
SqlBulkCopy
命令,但是现在它似乎没有在MiniProfiler的sql视图中记录它

SqlBulkCopy是否会有关联的命令字符串

是否可以将大容量副本显示在sql命令列表中

我至少可以将其计入%sql位吗


我知道我可以使用
MiniProfiler.Current.Step(“执行大容量复制”)
,但这不算作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);
}
公共静态void BulkInsertAll(此DataContext dc,IEnumerable实体)
{
var conn=(dc.Connection作为ProfiledDbConnection)。InnerConnection作为SqlConnection;
conn.Open();
类型t=类型(t);
var tableAttribute=(tableAttribute)t.GetCustomAttributes(
typeof(TableAttribute),false.Single();
var bulkCopy=new SqlBulkCopy(conn)
{
DestinationTableName=tableAttribute.Name
};
//....
bulkCopy.WriteToServer(表);
}

您应该能够使用
自定义计时来分析这些。这些都包含在现在的列表中

您可以看到
CustomTiming
的一些示例用法,其中它用于记录http和redis事件

有关如何将其与
SqlBulkCopy
一起使用的示例:

string sql = GetBulkCopySql(); // what should show up for the SqlBulkCopy event?
using (MiniProfiler.Current.CustomTiming("SqlBulkCopy", sql)) 
{
  RunSqlBulkCopy(); // run the actual SqlBulkCopy operation
}

数据将作为特殊的TDS数据包发送,但我不知道是否正在使用SQL启动
批量插入。它在SQL Profiler中显示为SQL,但这可能是假的。我正在努力添加一个更通用的
CustomTiming
类,允许您分析“大容量副本”,并让它以与“SQL”相同的方式显示在UI中。一旦它出来了,我就用一个例子来回答。@JarrodDixon:太好了!关于时间尺度(超过6-8周)有什么想法吗这个周末,我希望。。。今天就要开始内部测试了。@JarrodDixon:酷,看来我的问题时间安排得很好!