我有我的兩個不同的文件模式和映射,在我的映射類我這樣做:可空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導致編譯器錯誤,但我仍然想解決這個問題。有什麼想法嗎?