是否可以更改EF迁移“迁移”的位置?夹? [英] Is it possible to change the location of the EF Migrations "Migrations" folder?

查看:164
本文介绍了是否可以更改EF迁移“迁移”的位置?夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,add-migration命令尝试在以下目录中创建迁移.cs文件

By default, the add-migration command attempts to create the migration .cs file in


  • 项目根目录

    • 迁移

    我想存储我的迁移以及我与项目相关的\Data文件夹中与EF相关的代码的其余部分:

    I'd like to store my migrations along with the rest of my EF-related code in the \Data folder of my project:


    • 项目根

      • 数据

        • 迁移

        使用这种结构,当我执行时

        With this structure, when I execute

        PM> add-migration Migration1
        

        我收到以下错误:

        
            System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\MyProjectRoot\Migrations\201112171635110_Migration1.cs'.
           at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
           at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
           at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
           at System.IO.StreamWriter.CreateFile(String path, Boolean append)
           at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
           at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding)
           at System.IO.File.InternalWriteAllText(String path, String contents, Encoding encoding)
           at System.IO.File.WriteAllText(String path, String contents)
        

        是否可以指定磁盘上的位置在执行add-migration命令时应该创建迁移文件吗?

        推荐答案

        在配置类构造函数中添加此文件行:

        In the configuration class constructor add this line:

        this.MigrationsDirectory = "DirOne\\DirTwo";
        

        名称空间将继续设置为配置类本身的名称空间。要更改此设置,请添加以下行(也在配置构造函数中):

        The namespace will continue to be set as the namespace of the configuration class itself. To change this add this line (also in the configuration constructor):

        this.MigrationsNamespace = "MyApp.DirOne.DirTwo";
        

        这篇关于是否可以更改EF迁移“迁移”的位置?夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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