Entity Framework 4 SaveChanges not working and not throwing any error?

◇◆丶佛笑我妖孽 提交于 2019-12-06 08:59:38

Your public static ObjectContext CurrentFor() method will always create a new context. And your queries are using the ObjectContext property

public ObjectContext ObjectContext
{
    get { return ContextManager.CurrentFor(); }
}

Hence you are using multiple instances of ObjectContext. You are calling SaveChanges() of a different instance of ObjectContext. So no changes will be persisted.

Do not handle the transactions explicitly as you did in UnitOfWork. The ObjectContext will do that part.

Your design is a complicated abstraction. Try to use the framework as it is or find a simple Repository pattern which has already being tested an used.

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