我还不熟悉使用实体框架,我有两个Class对象,Loans和BalanceAndInterest。分别是一对多关系。
我能够设置要存储到Loans对象的对象,但我确定我应该如何将数据添加到BalanceAndInterest并保持其关系。
我以前只需要使用单个类对象,而且我真的知道是谁让这个工作。
类对象:
public class Loan
{
public Loan() {
BalanceAndInterest = new List<BalanceAndInterest>();
}
public int LoanID { get; set; }
public string LoanName { get; set; }
public DateTime LoanDueDate { get; set; }
public virtual ICollection<BalanceAndInterest> BalanceAndInterest { get; set; }
}
public class BalanceAndInterest
{
public BalanceAndInterest() { }
public int BalanceAndInterestId { get; set; }
public int CurrentBalance { get; set; }
public int InterestRate { get; set; }
public virtual Loan Loan { get; set; }
}
我正在尝试加载日期:
loan = new Loan
{
//LoanID
LoanName = tbxName.Text,
LoanDueDate = Convert.ToDateTime(datePickerFirstDueDate.Text),
BalanceAndInterest/// here were I'm getting lost
};