如何告诉Microsoft.AspNet.Identity.EntityFramework使用存储过程

时间:2015-10-13 17:43:30

标签: asp.net identity

我刚刚使用Microsoft.AspNet.Identity.EntityFramework 2.2.1创建了一个具有正常运行身份模型的项目。一切正常,期望它使用Insert语句。有没有办法我可以覆盖一些东西让它调用我自己的procs或使其使用存储过程?

1 个答案:

答案 0 :(得分:1)

使用Fluent API,您可以指定为您的用户实体使用存储过程。

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    //...

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        //Since it extends IdentityDbContext<T>
        base.OnModelCreating(modelBuilder);

        modelBuilder
            .Entity<ApplicationUser>()
            .MapToStoredProcedures(s =>
            {
                s.Insert(i => i.HasName("insert_user"));
            });
    }
}

https://msdn.microsoft.com/en-us/data/dn468673.aspx

相关问题