简体   繁体   English

无法使用实体框架(版本4.3.1)以调试方式调试到我的DbContext派生类代码中

[英]cannot debug into my DbContext derived class code using Entity Framework (ver 4.3.1) code-first

Here is my solution setup using VS 2012 Ultimate: 这是我使用VS 2012 Ultimate的解决方案设置:

I have a project (eg MyDomainModel) containing all the business domain types using POCO classes. 我有一个包含使用POCO类的所有业务域类型的项目(例如MyDomainModel)。 I have another project (eg MyEntity) referring to the MyDomainModel project and has the derived DbContext class (eg MyDbContext) implementing custom business logic (eg for automatic time-stamping when inserting and modifying data) in the SaveChanges method. 我有另一个项目(例如MyEntity)引用MyDomainModel项目,并且派生了DbContext类(例如MyDbContext),该类在SaveChanges方法中实现了自定义业务逻辑(例如,在插入和修改数据时进行自动时间戳记)。

I have another mstest based project (eg MyEntity_Tests) which will test the derived DbContext (eg MyDbContext) with known seeded data as part of the database initialization. 我有另一个基于mstest的项目(例如MyEntity_Tests),它将使用已知的种子数据测试派生的DbContext(例如MyDbContext),作为数据库初始化的一部分。

My problem is that when debugging the test, the breakpoint set on the MyDbContext's c# code is not hit. 我的问题是在调试测试时,未命中MyDbContext的c#代码上设置的断点。 However if I put lines such as Debug.Print("xxx") in the file and debugging the same test, the test output will contain those expected output "xxx". 但是,如果我在文件中放入诸如Debug.Print(“ xxx”)之类的行并调试同一测试,则测试输出将包含那些预期的输出“ xxx”。

I know that Entity Framework runtime will generate proxy dll behind scene to wrap those dlls (eg MyDomainModel.dll). 我知道Entity Framework运行时将在后台生成代理dll来包装这些dll(例如MyDomainModel.dll)。 However not being able to debug my own code as in MyDbContext is really a big problem to me. 但是,像MyDbContext一样无法调试自己的代码对我来说确实是一个大问题。 Do other people have the similar problem when using EF code-first and how to solve this problem? 其他人在使用EF代码优先时是否有类似的问题,以及如何解决此问题?

Set the breakpoint on a line in the derived DbContext class start debugging and hover the mouse over it to see why it is not hit. 在派生的DbContext类中的一行上设置断点,开始调试,并将鼠标悬停在该断点上,以查看为什么未命中该断点。 Most likely symbols are not loaded. 最有可能的符号未加载。 When debugging go to loaded modules window right click on your assembly and you can check where VS tried loading symbols from. 调试时转到已加载的模块窗口,右键单击程序集,然后可以检查VS尝试从何处加载符号。 You can also load your symbols manually. 您也可以手动加载符号。 Note that if symbols don't match the assembly you need to rebuild your project to get up-to-date symbols. 请注意,如果符号与程序集不匹配,则需要重建项目以获取最新的符号。 Another reason why a breakpoint is not hit may be because your source code does not match the assembly. 未命中断点的另一个原因可能是因为您的源代码与程序集不匹配。 You can uncheck the checkbox in Settings->Debugging to enable debugging on sources that don't match assemblies but debugging like this is painful and counter-productive. 您可以取消选中“设置”->“调试”中的复选框,以在与程序集不匹配的源上启用调试,但是这样的调试既痛苦又适得其反。 Again rebuilding should help. 同样,重建应该会有所帮助。 I am assuming you are trying debugging Debug versions of your assemblies and not Release ones. 我假设您正在尝试调试程序集的Debug版本,而不是Release版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用实体框架代码优先使用凭据创建数据库? - Cannot Create Database with credentials using Entity Framework Code-First? 使用代码优先的实体框架没有自动增量 - Using Entity Framework with code-first no autoincrement 使用Code-first Entity Framework过滤多个派生类 - Filter with multiple derived classes with Code-first Entity Framework 无法将基类对象转换为派生类型对象,实体框架代码优先 - Can't cast base class object to derived type object, Entity Framework code-first 调试代码优先的Entity Framework迁移代码 - Debug code-first Entity Framework migration codes 使用实体框架6,自定义代码优先迁移和CSharpMigrationCodeGenerator - Using Entity Framework 6, Custom Code-First Migrations & CSharpMigrationCodeGenerator 实体框架代码优先使用现有数据库时的好处 - Entity Framework Code-First Benefits when using existing database 在现有MySQL数据库上使用实体框架4.1 Code-First - Using entity framework 4.1 Code-First on existing MySQL database 使用实体框架代码优先映射多个关系的问题 - Problem mapping multiple relations using Entity Framework code-first 使用实体框架Code-First创建表,运行时 - Create Table, Run Time using entity framework Code-First
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM