2017-03-08 1 views
0

通知クラスのGigプロパティの[必須]属性を次の流暢なapi式で置き換えます。C#、EF6 - 流暢なAPIで必要な属性を置き換えます

public class NotificationConfiguration : EntityTypeConfiguration<Notification> 
{ 
    public NotificationConfiguration() 
    { 
     Property(n => n.Gig).IsRequired(); 
    } 
} 

私はそうした場合、コンパイラはエラーCS0453をスロー:

The type 'Gig' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'StructuralTypeConfiguration'<Notification>.Property<T>(Expression<Func<Notification, T>>)' 

私はこれが動作しない理由を、見ることができません。

ありがとうございます!

答えて

0

私の間違い;-) ギグはテーブル表現を持つオブジェクトなので、必須フィールドではなくそのテーブルのナビゲーションプロパティでなければなりません。コードは次のようになります:

public class NotificationConfiguration : EntityTypeConfiguration<Notification> 
{ 
    public NotificationConfiguration() 
    { 
     HasRequired(n => n.Gig); 
    } 
} 
関連する問題