ASP.Net身份 - 使用自定义模式 [英] ASP.Net Identity - Use custom Schema

查看:117
本文介绍了ASP.Net身份 - 使用自定义模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是第一次使用MVC5 + EF6 code与ASP.Net 1.0的身份,并希望有一个自定义模式中创建的表。即架构不是dbo架构。

我反向工程使用EF电动工具我DATABSE和在映射类中的所有其他表设置模式名称下面的

  this.ToTable(tableName值,SCHEMANAME);

我试着这样做的ASP.Net表,但它一直给我很多的错误,最终我放弃了。
如果我排除我的项目中,他们将被创建,但(逆向工程)ASP.Net身份表始终dbo架构

任何人都知道如何做到这一点?


解决方案

 公共类MyDbContext:EntityDbContext< ApplicationUser>
{
    公共DbSet< ApplicationUser>用户{搞定;组; }    公共MyDbContext():基地()
    {
    }    保护覆盖无效OnModelCreating(DbModelBuilder模型构建器)
    {
        //你可以在这里全球架构分配
        modelBuilder.HasDefaultSchema(SCHEMANAME);
    }
}

I am using MVC5 + Ef6 code first with ASP.Net Identity 1.0 and wish to have the tables created in a custom schema. i.e. a schema that is not the dbo schema.

I reversed engineered my databse using the Ef power tools and set the schema name for all other tables in the mapping class to the following

this.ToTable("tableName", "schemaName");

I tried doing this for the ASP.Net tables but it kept giving me a lots of errors and eventually I gave up. If I exclude the (reverse engineered) ASP.Net Identity tables from my project they will be created but always in the dbo schema

Anyone know how to do this?

解决方案

public class MyDbContext : EntityDbContext<ApplicationUser>
{
    public DbSet<ApplicationUser> Users { get; set; }

    public MyDbContext() : base()
    {
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        // You can globally assign schema here
        modelBuilder.HasDefaultSchema("schemaName");
    }
}

这篇关于ASP.Net身份 - 使用自定义模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆