EF 4.1 code首先 - OnModelCreating通话时间 [英] EF 4.1 Code First - OnModelCreating call time

查看:196
本文介绍了EF 4.1 code首先 - OnModelCreating通话时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我调试我的应用程序这种方法似乎并没有被执行的的DbContext的构造背景。因此,它被调用的时候呢?

When I debug my application this method seems not to be executing in constructor context of DbContext. So when it is called then?

推荐答案

该方法被调用时,EF需要访问数据库的第一次(所以它不是在上下文中实例化)。如果数据库不存在,它将使用编译模型的信息来创建它。只有一次,每个应用程序(它在内部缓存),因此,即使在废弃的背景下您的模型将仍然重复使用下一个实例被创建的模型。

This method is called when EF needs to access database for the first time (so it is not during context instancing). If the database doesn't exists it uses information from compiled model to create it. The model is created only once per application (it is cached internally) so even if you dispose the context your model will be still reused for the next instance.

这篇关于EF 4.1 code首先 - OnModelCreating通话时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆