저는 ASP.NET Core와 EF Core를 사용하고 있으며, 다음 두 개의 부모 클래스와 하위 클래스가 있습니다. 각 선물 카드는 많은 트랜잭션을 가질 수데이터 주석이있는 EF 핵심 마이그레이션에서 외래 키를 NOT NULL로 만드는 방법은 무엇입니까?
내가 읽은 것을 바탕으로public class GiftCard
{
public int Id { get; set; }
public string BarCode { get; set; }
public DateTime PurchaseDate { get; set; }
public string Comments { get; set; }
public byte[] Timestamp { get; set; }
public List<Transaction.Transaction> Transactions { get; set; }
}
public class Transaction
{
public int Id { get; set; }
public DateTime TransactionDate { get; set; }
public decimal TransactionAmount { get; set; }
public TransactionType TransactionType { get; set; }
public byte[] Timestamp { get; set; }
public GiftCard.GiftCard GiftCard { get; set; }
}
,이 아이의 부모와 참조 탐색에 대한 탐색을 갖는함으로써, 할 수있는 방법입니다. 마이그레이션을 추가하고 명령 줄을 사용하여 데이터베이스를 업데이트하면 Transactions 테이블의 GiftCardId 외래 키가 Null 인 것을 제외하고는 데이터베이스에서 모든 것이 정상적으로 보였습니다. 이 NULL이 아닌지 확인하고 싶습니다. Data Annotation 속성이 누락 되었습니까?