简体   繁体   English

实体框架4.1伪造dbcontext

[英]entity framework 4.1 faking dbcontext

Im using the entity framework 4.1 and have followed a tutorial to fake the dbcontext to mock and do unit tests. 我使用实体框架4.1并遵循教程假冒dbcontext来模拟并进行单元测试。 Everything works as expected with this. 一切都按预期工作。 ive amended the original dbcontext to return idbset's however when i recreated my model it overwrote this. 我修改了原始的dbcontext以返回idbset,但是当我重新创建我的模型时,它覆盖了这个。 This is to be expected i suppose but wondered whether there is away i can stop this happening. 我想这是可以预料的,但想知道是否有可能我可以阻止这种情况发生。 Any ideas? 有任何想法吗?

Probably the easiest approach is to replace the T4 templates that do the code generation with your own – copy the default templates into your project and adapt them to generate the code you want. 可能最简单的方法是用自己的代码替换用于生成代码的T4模板 - 将默认模板复制到项目中并调整它们以生成所需的代码。

MSDN has an introduction: http://msdn.microsoft.com/en-us/data/gg558520 MSDN有一个介绍: http//msdn.microsoft.com/en-us/data/gg558520

You can also use moles. 你也可以使用痣。 But I like the t4 template better. 但我更喜欢t4模板。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM