EF映射:名称末尾带有1的不需要的列

时间:2016-12-19 15:37:16

标签: c# entity-framework entity-framework-6

我有一个类CurrentPage,它有一个Page属性,它是一个枚举(int类型):

namespace App.Model.Application
{
    using System.Runtime.Serialization;

    /// <summary>
    /// Represents user the current page of a user in the application
    /// </summary>
    [DataContract]
    public class CurrentPage
    {
        /// <summary>
        /// Gets or sets the unique identifier for this current page.
        /// </summary>
        [DataMember]
        public int Id { get; set; }

        /// <summary>
        /// Gets or sets the description 
        /// </summary>
        [DataMember]
        public string Description { get; set; }

        /// <summary>
        /// Gets or sets the identifier of the current page to which the user has navigated.
        /// </summary>
        [DataMember]
        public Page Page { get; set; }

        /// <summary>
        /// Gets or sets the current page as an integer; this is to support Entity Framework limitations regarding enumerations.
        /// </summary>
        public int PageId
        {
            get
            {
                return (int)this.Page;
            }

            set
            {
                this.Page = (Page)value;
            }
        }
    }
}

它的映射如下:

this.Property(cp => cp.Page).IsRequired();

如果我尝试在VisualStudio中运行Add-Migration,我最终会在迁移代码

中获取此内容
RenameColumn(table: "dbo.CurrentPage", name: "Page1", newName: "Page");

我不明白这个'Page1'这个名字的来源。数据库中没有Page1列。

有什么想法吗?是否可以创建Page1列,因为它以某种方式认为已经存在的Page列不适合映射到该属性?

1 个答案:

答案 0 :(得分:0)

不是100%确定原因是什么,但我删除了PageId属性并删除了我所有的现有迁移。然后我重新启动了Visual Studio(fwiw)。运行了update-database -script,最后添加了一个新的迁移(Add-Migration MyNewMigration),这一切都重新开始了。我知道这不是一个非常令人满意的答案,但它现在正在运作。在完成所有这些操作之前,我还获得了数据库的全新副本,未触及我的模型更改。

相关问题