调用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");
...
其他信息......
因为错误是
无效的列名称“Loan_ID”。
无效的列名称“Loan_ID1”。
我将这两列添加到我的LON_LEDGER TABLE ..
所以它看起来像这样
/ LON_LEDGER TABLE
LON_LEDGER_ID LON_ID DTM_POSTED 描述 AMT PAY_ID LEDGER_TYPE_FLG LOAN_ID LOAN_ID1 错误消失了..
这个真正流畅的API是否有效?
那个LOAN_ID&amp; LOAN_ID1应该是我桌子上的LON_ID列...以及为什么有2列?
即使这两列都是null ..我的代码工作正常,只要它在那里..
希望它会让读者了解更多......
这里需要真正的帮助..