我在两个不同的文件上有我的模型和映射,在我的映射类上我这样做:
public class UserEmailMap : EntityTypeConfiguration<UserEmail> {
HasKey(t => new { t.UserId, t.EmailId });
Property(t => t.UserId)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
Property(t => t.EmailId)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
ToTable("UsersEmails");
Property(t => t.UserId).HasColumnName("UserId");
Property(t => t.EmailId).HasColumnName("EmailId");
Property(t => t.IsPrimary).HasColumnName("IsPrimary");
HasRequired(t => t.Email)
.WithMany(t => t.UserEmails)
.HasForeignKey(d => d.EmailId);
HasRequired(t => t.User)
.WithMany(t => t.UserEmails)
.HasForeignKey(d => d.UserId);
}
现在,视觉工作室抱怨这些行:
Property(t => t.UserId)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
Property(t => t.EmailId)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
它强调了两者DatabaseGeneratedOption.None
有了这个消息:Argument type 'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption' is not assignable to parameter type 'System.Nullable<System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption>'
。
我试过这个:
Nullable<DatabaseGeneratedOption> x1 = DatabaseGeneratedOption.None;
DatabaseGeneratedOption? x2 = DatabaseGeneratedOption.None;
Property(t => t.UserId)
.HasDatabaseGeneratedOption(x1);
Property(t => t.EmailId)
.HasDatabaseGeneratedOption(x2);
这是意想不到的部分:
Argument type 'System.Nullable<System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption> [mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]' is not assignable to parameter type 'System.Nullable<System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption> [mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]'
x1
和上的相同消息x2
。
这不会导致编译器错误,但我仍然想解决这个问题。有什么想法吗?