EF迁移,在将其设置为数据库生成的标识时与属性标识冲突

时间:2012-09-25 21:21:52

标签: c# entity-framework ef-code-first

我为我的身份类设置了这个设置:

   public class Identity 
   {
        public Identity()
        {
            this.Roles = new List<Role>();
        }

        public int Id { get; set; }
        public System.DateTime DateAdded { get; set; }
        public string identityprovider { get; set; }
        public string nameidentifier { get; set; }
        public System.DateTime LastLoggedIn { get; set; }

        public virtual ICollection<Role> Roles { get; set; }
    }

public class IdentityMap : EntityTypeConfiguration<Identity>
{
    public IdentityMap()
    {
        // Primary Key
        this.HasKey(t => t.Id);

        // Properties
        this.Property(t => t.identityprovider)
            .IsRequired()
            .HasMaxLength(255);

        this.Property(t => t.nameidentifier)
            .IsRequired();

        // Table & Column Mappings
        this.ToTable("Identities");
        this.Property(t => t.Id).HasColumnName("Id")
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
//ERROR WHEN ADDING ABOVE LINE DatabaseGeneratedOption.Identity


        this.Property(t => t.DateAdded).HasColumnName("DateAdded").
            HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);
        this.Property(t => t.identityprovider).HasColumnName("identityprovider");
        this.Property(t => t.nameidentifier).HasColumnName("nameidentifier");
        this.Property(t => t.LastLoggedIn).HasColumnName("LastLoggedIn")
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);

        // Relationships
        this.HasMany(t => t.Roles)
            .WithMany(t => t.Identities)
            .Map(m =>
                {
                    m.ToTable("IdentityRoles");
                    m.MapLeftKey("Identities_Id");
                    m.MapRightKey("Roles_Id");
                });


    }
}

尝试添加迁移时出现以下错误:

  

为属性“Id”指定了冲突的配置设置   输入'S_Innovations.TrafficTheory.EFModel.Models.Identity':     DatabaseGeneratedOption =身份与之冲突   DatabaseGeneratedOption =无

0 个答案:

没有答案