Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
697 views
in Technique[技术] by (71.8m points)

entity framework - How can I disable code first migrations

I have a code-first entity model in EF5. But I want to manage the database changes manually -- I do not want EF to modify my existing database and all its data. But when I make parallel changes in the EF mapping and in the database, EF refuses to operate properly telling me I need to use code first migration. How do I turn this off?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

set the Database.SetInitializer to null.

public class DatabaseContext: DbContext
{
    //the base accepts the name of the connection string provided in the web.config as a parameter
    public DatabaseContext()
        : base("DatabaseContext")
    {
        //disable initializer
        Database.SetInitializer<DatabaseContext>(null);
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...