与实体框架的身份context.SaveChanges不将数据保存到数据库

时间:2016-11-26 19:24:27

标签: c# asp.net-mvc entity-framework asp.net-identity unit-of-work

我在ASP.NET MVC应用中定制了identity。我创建了一个StoreService来实现IUserStore身份接口。当我调用ApplicationUsermanager的创建方法时,它会点击createAsync的{​​{1}}方法。该方法成功执行,但用户记录永远不会插入数据库。

我使用StoreService和存储库模式还有一件事。我已经为UnitOfWork注册了上下文类。

我调试了这个方法,并探索了上下文对象,我觉得一切都很好,有正确的连接字符串

这是我的代码:

Unityconfig

StoreService

的UserManager

public static void RegisterTypes(IUnityContainer container)
{
        // NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements.
        // container.LoadConfiguration();

        // TODO: Register your types here
        // container.RegisterType<IProductRepository, ProductRepository>();
        container.RegisterType<DbContext, StoreContext>(new HierarchicalLifetimeManager());
        container.RegisterType<StoreContext>(new HierarchicalLifetimeManager());
        container.RegisterType<IUserStore<Users, long>, newfrontiemvc.InfraStructure.StoreService.UserStoreService>(new InjectionConstructor(new StoreContext()));
}

private ApplicationUserManager _userManager; public ApplicationUserManager AppUserManager { get { return _userManager ?? _iOwinContext.Get<ApplicationUserManager>(); } private set { _userManager = value; } } public Result<long> CreateUser(Users newUser, ControllerBase controllerBase) { var returnVal = AppUserManager.Create(newUser, newUser.Password); // I got returnVal.Succeeded=true here if (returnVal.Succeeded) { } return result; }

StoreService

我很困惑的是身份相关的错误或实体框架错误。

当我使用相同的上下文从public Task CreateAsync(Users user) { _context.User.Add(user); return _context.SaveChangesAsync(); } 表中获取数据时,它会显示数据,但我无法保存新记录。

有任何帮助吗?提前致谢

0 个答案:

没有答案
相关问题