Asp.net mvc 3 首先分析EF数据库仍然存在问题

Asp.net mvc 3 首先分析EF数据库仍然存在问题,asp.net-mvc-3,entity-framework-4.1,mvc-mini-profiler,Asp.net Mvc 3,Entity Framework 4.1,Mvc Mini Profiler,使用EF 4.1和Mini profiler 1.7。首先使用模型,从现有数据库扫描。EF生成的类派生自ObjectContext/ObjectSet,而不是DbContext/DbSet。我找不到任何地方可以控制它 我尝试了流行的解决方案,但没有结果 受挫折之苦,我还尝试直接使用显式EntityConnection创建上下文,它是直接使用ProfiledDbConnection创建的。我想绕过连接不是预期类型的任何可能性 公共家庭控制器(){ 试一试{ 字符串[]路径=新字符串[]{@“res

使用EF 4.1和Mini profiler 1.7。首先使用模型,从现有数据库扫描。EF生成的类派生自ObjectContext/ObjectSet,而不是DbContext/DbSet。我找不到任何地方可以控制它

我尝试了流行的解决方案,但没有结果

受挫折之苦,我还尝试直接使用显式EntityConnection创建上下文,它是直接使用ProfiledDbConnection创建的。我想绕过连接不是预期类型的任何可能性

公共家庭控制器(){
试一试{
字符串[]路径=新字符串[]{@“res://*/”};
Assembly[]assys=新程序集[]{Assembly.getExecutionGassembly()};
MetadataWorkspace mw=新的MetadataWorkspace(路径、关联);
字符串cnx=WebConfiguration Manager.ConnectionString[“XXXX”]。ConnectionString;
DbConnection cx=MvcMiniProfiler.Data.ProfiledDbConnection.Get(新的SqlConnection(cnx),MiniProfiler.Current);
//DbConnection cx=数据库.DefaultConnectionFactory.CreateConnection(cnx);
EntityConnection ec=新的EntityConnection(mw,cx);
db=新的MyContexties(ec);
}
捕获(例外情况除外){
Trace.WriteLine(“EDM失败:+ex.Message”);
db=新的myContexties();
}
}
我已确认所采取的路径是正确的。但是,当实际运行LINQ查询时,我们会遇到一个异常:

无法强制转换类型为的对象 “MvcMiniProfiler.Data.ProfiledDbConnection”到类型 “System.Data.SqlClient.SqlConnection”

令人不快的说法是:

returnquery.ToList();
堆栈跟踪更有趣,因为显然EF中的某些东西绝对需要SqlConnection

在System.Data.SqlClient.SqlCommand.set_DbConnection(DbConnection值)处 at System.Data.Common.DbCommand.set_Connection(DbConnection值) 位于System.Data.Common.Utils.CommandHelper.SetStoreProviderCommandState(EntityCommand entityCommand、EntityTransaction、EntityTransaction、DbCommand storeProviderCommand) 位于System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand,CommandBehavior) 在System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext)中 上下文,ObjectParameterCollection参数值) 在System.Data.Objects.ObjectQuery中
1.GetResults(可为Nullable
1 forMergeOption) 在System.Data.Objects.ObjectQuery
1.System.Collections.Generic.IEnumerable.GetEnumerator()中
位于System.Collections.Generic.List
1..ctor(IEnumerable
1集合)
at System.Linq.Enumerable.ToList[t源](IEnumerable
1源)

显然,如果我给它提供一个SqlConnection,一切都会很好

这是怎么回事?这是怎么回事?也许这对EDMX的案子不起作用?它是ObjectContext派生的这一事实是否有任何关系?

升级EF(4.1.10715.0)和MiniProfiler(1.9.1)包,并添加MiniProfiler.EF(1.9.1)包后,进入应用程序启动模块(MiniProfiler.cs)并放入以下内容,而不是
ProfiledDbConnectionFactory
代码:

MiniProfilerEF.Initialize();

一切都很好

我也遇到同样的问题。仍然没有解决方法:(您是否有可能使用EF 4.1‘更新1’?根据NuGet软件包,我正在使用EF 4.1.10330.0和MiniProfiler 1.7。我发现这两个软件包都有更新版本,更新是否合适?