1
我有一个实体框架CodeFirst类(POCO)客户端:使用接口/抽象类与实体框架CodeFirst
void context_SavingChanges(object sender, EventArgs e)
{
foreach (ObjectStateEntry entry in
((ObjectContext)sender).ObjectStateManager.GetObjectStateEntries(
EntityState.Added | EntityState.Modified | EntityState.Deleted))
{
IMyContract myContract = entry.Entity as IMyContract;
if(myContract != null)
{
...
}
}
}
我用这个来获取Context对象:var context =((IObjectContextAdapter)database).ObjectContext; context.SavingChanges + = new EventHandler(context_SavingChanges); – Attilah 2011-04-04 07:39:12
问题不在于ObjectContext,而在于它永远不会评估为真:DiscountEntity discountEntity = entry.Entity as DiscountEntity; – Attilah 2011-04-04 07:52:17
如果您调试您的应用程序,您在监视窗口中看到了什么类型的实体? – 2011-04-04 08:04:26