代码之家  ›  专栏  ›  技术社区  ›  Govind K

如何在Entity Framework 6中读取\uu MigrationHistory中的所有数据

  •  -1
  • Govind K  · 技术社区  · 7 年前

    我想从在Entity Framework 6中自动创建的\uu MigrationHistory表中读取数据。这可能吗?否则,从迁移历史记录表中读取数据的可能方法是什么?C中的那个#

    2 回复  |  直到 7 年前
        1
  •  1
  •   Amicable    5 年前

    我真的不想将迁移历史记录表完全挂接到EF中,因为我不希望人们写入或更新该表,而该表应该完全由自动/手动迁移来处理。

    因此,如果我需要访问它,我会使用SQL字符串来执行我所需要的操作

        class MigrationHistoryEntry
        {
            public string MigrationId { get; set; }
            public string ContextKey { get; set; }
            public byte[] Model { get; set; }
            public string ProductVersion { get; set; }
        }
    
        public void GetMigrations()
        {
            const string GetMigrationSql = "SELECT * FROM __MigrationHistory";
    
            var migrations = Context.Database.SqlQuery<MigrationHistoryEntry>(GetMigrationSql);
        }
    
        2
  •  0
  •   David Browne - Microsoft    7 年前

    从迁移历史记录表中读取数据的可能方法是什么?

    有一个专门用于读取表中数据的SQL命令: SELECT