我在我的MVC 3.0应用程序中使用实体框架4.1。该应用程序是一个n层方法,我的UI,Model,Classes,Services和Repository都在一个解决方案中放入不同的项目中。我还使用了工作单元方法和依赖注入,因此我无法访问UI中的DbContext。保存新记录后不能延迟加载实体
我有两个班像下面
public partial class Form
{
public int id { get; set; }
public int eventID { get; set; }
public string sampleName { get; set; }
public virtual Event GetEvent{ get; set; }
}
public partial class Event
{
public int id { get; set; }
public string eventName { get; set; }
}
然后在我的控制,我想补充类形态的实例,这样
Form _form = new Form();
_form.eventID = 3;
_form.sampleName = "myString";
_formService.AddForm(_form);
_formService.SaveChanges(); //This calls the Unit of Work Commit
这个工程并插入记录到数据库中。但随后在调用SaveChanges下面几行()调用我尝试延迟加载相关的事件类这样
string _eventName = _form.GetEvent.eventName;
但价值_form.GetEvent
始终为NULL。它看起来像GetEvent
尚未加载。
任何人都可以帮助我吗?
在此先感谢。