Navigation properties not set when using ADO.NET Mocking Context Generator

こ雲淡風輕ζ 提交于 2019-12-12 03:03:48

问题


I am using ADO.NET Mocking Context Generator plugin for my Entity Framework model. I have not started on using mocks yet, just trying to fix generated entity and context classes to make application run as before without exceptions. I've already fixed T4 template to support SaveChanges method.

Now I've got another problem: when I try to access any navigation property it is set to null. All the primitive fields inherited from DB table are set and correct.

So what I am doing is the following

using (var context = MyContext())
{
      var order = context.Orders.Where(p => p.Id == 7);
      var product = order.Products;
}

in this case product is set to null. But that was not a case while using default code generator, it used to return real product object.

Thanks ahead for any suggestions!


回答1:


I tried to fix t4 template and nothing helped. So I gave up on ADO.NET Mocking Context Generator template and switched to ADO.NET POCO Entity Generator template. I followed the steps mentioned here http://slappyza.wordpress.com/2010/08/08/getting-the-entity-framework-to-generate-an-interface-for-mocking/ But instead of RhinoMock for testing I used Moq library.

And it finally worked!



来源:https://stackoverflow.com/questions/8335489/navigation-properties-not-set-when-using-ado-net-mocking-context-generator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!