调用member.TotalBalance
时出现无效的列错误无效的列名称“Loan_ID”。
无效的列名称“Loan_ID1”。
继承我的片段
public class Member
{
public string ID { get; set; }
private ICollection<Loan> _Loans;
public virtual ICollection<Loan> Loans
{
get { return _Loans ?? (_Loans = new HashSet<Loan>()); }
set { _Loans = value; }
}
public virtual double TotalBalance
{
get
{
return Loans.Select(p => p.TotalBalance).Sum();
}
}
}
public class Loan
{
public string ID { get; set; }
public string MemberId { get; set; }
private ICollection<LoanLedger> _LoanLedgers;
public virtual ICollection<LoanLedger> LoanLedgers
{
get { return _LoanLedgers ?? (_LoanLedgers = new HashSet<LoanLedger>()); }
set { _LoanLedgers = value; }
}
public virtual double TotalBalance
{
get
{
return LoanLedgers.Select(p => p.Amt).Sum();
}
}
}
public class LoanLedger
{
public string ID { get; set; }
public double Amt { get; set; }
public string LoanId { get; set; }
}
以下是它在EF中的配置
//会员
HasKey(b => b.ID).Property(b => b.ID).HasColumnName("MBR_ID")
...
//贷款
HasKey(p => p.ID).HasRequired(a => a.Member).WithMany(i => i.Loans);
HasKey(p => p.ID).Property(p => p.ID).HasColumnName("LON_ID")
Property(p => p.MemberId).HasColumnName("MBR_ID");
...
// LoanLedger
HasKey(p => p.ID).HasRequired(a => a.Loan).WithMany(p => p.LoanLedgers);
HasKey(b => b.ID).Property(b => b.ID).HasColumnName("LON_LEDGER_ID")
Property(b => b.LoanId).HasColumnName("LON_ID");
...
提前致谢。