如何美元,建立一个数据库和表p $ pvent实体分贝范围内? [英] How to prevent entity db context from create a database and tables?

查看:109
本文介绍了如何美元,建立一个数据库和表p $ pvent实体分贝范围内?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET MVC 5网站与EF身份。但我想创建数据库,并使用我之前生成的SQL脚本的数据库表。但每次我会尝试登录例如的DbContext创建一个新的数据库和表(如果不存在的话)。如何只是抛出一个异常,而不是创造,如果不存在的话,如果它存在,只是做了正常登录

I have a ASP.NET MVC 5 website with EF for identity. But i would like to create the database and the database tables using the sql scripts that i generated before. But everytime i will try to login for example the dbcontext creates a new database and the tables (if it not exists). How to just throw an exception and not create if it not exist, and if it exist, just do the login normally.

我的上下文类:

 public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
 {
    public ApplicationDbContext()
        : base("DefaultConnection")
    {
    }
 }

在我试图重写onmodelCreating方法只是抛出一个异常,但比即使数据库的表格存在,它表明我的异常。

The i tried to override the onmodelCreating method just throwing an exception, but than even if the database exists with the tables, it shows me that exception.

推荐答案

尝试添加这是你的上下文中:

Try adding this inside your context:

Database.SetInitializer<ApplicationUser>(null);

这将关闭数据库初始化和迁移

It will turn off database initialization and migrations

这篇关于如何美元,建立一个数据库和表p $ pvent实体分贝范围内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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