我有我的两个不同的文件模式和映射,在我的映射类我这样做:可空DatabaseGeneratedOption是不能分配给参数类型可空DatabaseGeneratedOption
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);
}
现在,Visual Studio是抱怨这些行:
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
同样的信息。
This does not导致编译器错误,但我仍然想解决这个问题。有什么想法吗?