重现问题的步骤:
我正在使用最新的6/20/2011(1.3),使用NuGet,MVC3,VS2010,Knockout.js和jQuery 1.5.2.
有人有什么想法吗?
编辑:我已经加入这是一个问题在这里.
使用EF 4.1和Mini-profiler 1.7.使用模型优先,从现有数据库扫描.EF生成一个派生自ObjectContext/ObjectSet的类,而不是DbContext/DbSet.我无法找到控制它的地方.
我尝试了流行的解决方案,但无济于事.
由于受挫,我还尝试使用显式的EntityConnection直接创建我的Context,这是直接使用ProfiledDbConnection创建的.我想绕过任何连接不是预期类型的机会.
public HomeController() {
try {
string[] paths = new string[] { @"res://*/" };
Assembly[] assys = new Assembly[] { Assembly.GetExecutingAssembly() };
MetadataWorkspace mw = new MetadataWorkspace(paths, assys);
string cnx = WebConfigurationManager.ConnectionStrings["XXXX"].ConnectionString;
DbConnection cx = MvcMiniProfiler.Data.ProfiledDbConnection.Get(new SqlConnection(cnx), MiniProfiler.Current);
//DbConnection cx = Database.DefaultConnectionFactory.CreateConnection(cnx);
EntityConnection ec = new EntityConnection(mw, cx);
db = new MyContextEntities(ec);
}
catch (Exception ex) {
Trace.WriteLine("EDM failed: " + ex.Message);
db = new MyContextEntities();
}
}
Run Code Online (Sandbox Code Playgroud)
我已经验证了正确的路径.但是,当实际运行LINQ查询时,我们得到一个异常:
无法将类型为"MvcMiniProfiler.Data.ProfiledDbConnection"的对象强制转换为"System.Data.SqlClient.SqlConnection".
违规声明是:
return query.ToList();
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪更有趣,因为显然EF内部的东西绝对需要SqlConnection!
在system.Data.SqlClient.SqlCommand.set_DbConnection(DbConnection值)处于System.Data.Common.Utils.CommandHelper.SetStoreProviderCommandState(EntityCommand entityCommand,EntityTransaction …
使用迷你探查器时,这是否意味着生产代码将使用块"乱丢"?
using (profiler.Step("Set page title"))
{
ViewBag.Title = "Home Page";
}
Run Code Online (Sandbox Code Playgroud)
我想如果它是一次性测试我可以删除它,但通常你想将它们保存在代码库中以进行持续分析.
我想将MVCMiniProfiler与Dapper一起使用.除了在"使用Profiler.Step"块中包装来自dapper的"查询"调用之外,这是否可能?
我有这个基本的Dapper电话:
Dim comments As List(Of Comment)
Using conn = New SqlConnection(ConnectionString)
conn.Open()
comments = conn.Query(Of Comment)("SELECT * from comments where userid = @userid", New With {.userid= 1})
End Using
Run Code Online (Sandbox Code Playgroud)
MiniProfiler示例显示了这一点
Private Shared _sqlConnection As SqlConnection
Public Shared Function GetOpenConnection() As DbConnection
If _sqlConnection Is Nothing Then
_sqlConnection = New SqlConnection("connection string")
End If
' wrap the connection with a profiling connection that tracks timings
Return MvcMiniProfiler.Data.ProfiledDbConnection.[Get](_sqlConnection, MiniProfiler.Current)
End Function
Run Code Online (Sandbox Code Playgroud)
我陷入困境的是在ProfiledDbConnection上执行"Get".使用Dapper时是否可以使用ProfiledDbConnection?
EF 4.1 Update 1在分析方面有一个错误,现在已修复,我正在尝试使用MySql和EF 4.2 Code First进行分析.
我尝试过
MiniProfilerEF.Initialize();
在我的应用程序启动但收到错误
无法找到请求的.Net Framework数据提供程序.它可能没有安装.
我有一个ASP.NET MVC3项目,主要的aspx页面使用jQuery ajax为其部件进行动态加载.所以基本上当网站加载时,它命中/ Home/Index然后在Index(aspx)视图中,有几行jQuery进行ajax调用(到/ Home/PartOne和/ Home/PartTwo来填充页面的部分内容).
因此,每次加载页面时,它基本上都会执行3个请求:获取索引,获取PartOne,然后获取PartTwo.
问题:为什么第三个请求执行会有某种"等待"时间?我认为这是浏览器并发请求限制,但为什么不在第一个请求完成后执行?
当我通过实验性地将"OutputCache"属性放在"PartTwo"上时,它表现得如预期的那样,它正在快速执行.这暗示问题不在IIS中,而是在此之后以及在它触及我的action方法之前的某个地方.
以下是Chrome网络探查器的屏幕截图:

这是MvcMiniProfiler上的屏幕截图 - 查看第3行/值,它在执行我的控制器动作代码之前等待500ms.

我的控制器代码看起来像这样.虽然我剪断了实际的代码,但PartTwo的代码非常简单(没有长时间的计算,没有数据库调用等):
public class HomeController : Controller {
public ActionResult Index() {
// do something here
return View();
}
public ActionResult PartOne() {
// do something here
return View();
}
public ActionResult PartTwo() {
// do something here
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
我的javascript:
$(document).ready(function () {
$.ajax({
url: "/Home/PartOne",
cache: false,
success: function (data, textStatus, request) {
$("#TestContainerOne").html(data);
}
});
$.ajax({
url: "/Home/PartTwo",
cache: false,
success: function (data, …Run Code Online (Sandbox Code Playgroud) ajax asp.net-mvc performance asp.net-mvc-3 mvc-mini-profiler
我厌倦了安装MiniProfiler,使用http://miniprofiler.com/上的HowTo
这似乎有效:
<%= StackExchange.Profiling.MiniProfiler.RenderIncludes() %>
Run Code Online (Sandbox Code Playgroud)
但是,当我启动该网站时,我收到此错误消息:
'MiniProfiler' is undefined
Run Code Online (Sandbox Code Playgroud)
问题在于包含的MiniProfiler代码:
var initMp = function(){
load('/mini-profiler-resources/includes.js?v=6cJT7lsVkH6SxAlFpQstk1/AgtUwMUApXN3pviVvaRE=',function(){
MiniProfiler.init({.....
Run Code Online (Sandbox Code Playgroud)
当我尝试http://localhost/mini-profiler-resources/includes.js?v=6cJT7lsVkH6SxAlFpQstk1/AgtUwMUApXN3pviVvaRE=用IE 打开时,我得到了404.
我甚至试过在stackoverflow上找到这个解决方案,但它对我不起作用:(
有人知道这个问题,或者知道我能做些什么来解决这个问题?
我通过添加此解决方案的" 配置"部分和"runAllManagedModulesForAllRequests"行解决了该问题:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<handlers>
<add name="UrlRoutingModule1" path="mini-profiler*.js" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
<add name="UrlRoutingModule2" path="mini-profiler*.css" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
<add name="UrlRoutingModule3" path="mini-profiler*.tmpl" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
</handlers>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
"技巧"是添加下面的行以使处理程序工作.
<modules runAllManagedModulesForAllRequests="true"/>
Run Code Online (Sandbox Code Playgroud) 该MiniProfiler网站给出了生成实体框架下面的代码ObjectContext:
public static MyModel Get()
{
var conn = new StackExchange.Profiling.Data.EFProfiledDbConnection(GetConnection(), MiniProfiler.Current);
return ObjectContextUtils.CreateObjectContext<MyModel>(conn); // resides in the MiniProfiler.EF nuget pack
}
Run Code Online (Sandbox Code Playgroud)
但是,使用Entity Framework 5,我没有使用ObjectContext- 而是我使用的是DbContext.我不能在这里插入模型名称,因为该CreateObjectContext<T>()方法需要T是类型ObjectContext.(出于同样的原因,此答案中给出的代码也不起作用).
另外,我使用autofac来初始化我的Db连接.这是使用以下内容注册的(MyData=我的EF DataContext的名称):
Builder.RegisterType<MyData>().As<DbContext>().InstancePerHttpRequest();
Run Code Online (Sandbox Code Playgroud)
因此结合两部分:如何使用autofac初始化与MiniProfiler.EF绑定的DbContext?如果这是不可能的,至少我怎么做第一部分(为MiniProfiler.EF创建一个工厂方法来返回DbContext)?
我喜欢我的.NET项目的MiniProfiler.但是,我遇到了一个问题.分析器实际上导致查询略有不同,这导致错误.例如,当未初始化探查器时,将生成包含的SQL查询nvarchar(4000).但是,在初始化分析器的情况下,查询的该部分已更改为nvarchar(max).这会导致以下SqlException:
全文查询字符串的全文查询参数无效.
我没有找到任何有类似问题的人.
一种解决方案是能够在执行此特定查询之前以某种方式动态地初始化MiniProfiler,以便对于这一个查询,将使用默认的DBProviderFactory而不是MiniProfiler的DBProviderFactory.但是,这似乎不受支持.
我在MVC 4应用程序上使用MiniProfiler.我们有一个视图以模态呈现(使用Colorbox jquery插件).那个视图在其中有一个局部视图,其中ajax形式如下所示:
@using(Ajax.BeginForm("<action name>", "<controller name>", new {area="<area name>"}, new AjaxOptions
{
UpdateTargetId = "modal-body",
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST"
}))
{
<html for form here>
}
Run Code Online (Sandbox Code Playgroud)
当我们提交表单时,它返回相同的局部视图以覆盖视图上的整个部分.发布时,MiniProfiler会抛出错误:SyntaxError:意外的令牌,
这发生在这个函数中:
var jQueryAjaxComplete = function (e, xhr, settings) {
if (xhr) {
// should be an array of strings, e.g. ["008c4813-9bd7-443d-9376-9441ec4d6a8c","16ff377b-8b9c-4c20-a7b5-97cd9fa7eea7"]
var stringIds = xhr.getResponseHeader('X-MiniProfiler-Ids');
if (stringIds) {
var ids = typeof JSON != 'undefined' ? JSON.parse(stringIds) : eval(stringIds);
fetchResults(ids);
}
}
};
Run Code Online (Sandbox Code Playgroud)
它期待一个json的guids数组,但是它得到了两次数组,如下所示:
"["6de0e02c-e694-4d8a-ac22-ea6a847efe0e","970f6640-fe5b-45d9-bf59-c916b665458d"],["6de0e02c-e694-4d8a-ac22-ea6a847efe0e","970f6640-fe5b-45d9-bf59-c916b665458d" "]"
这会导致它在尝试解析数组时发出呕吐.我不确定为什么数组会重复.任何帮助将不胜感激.谢谢!
ajax ×2
asp.net-mvc ×2
.net ×1
autofac ×1
c# ×1
c#-4.0 ×1
dapper ×1
dbcontext ×1
performance ×1
sqlexception ×1