2

我通过它的 id 从数据库中检索现有客户。该客户有一个证书列表。所以我有:customer.CertificatesAsInvestor

当我创建一个新证书 ( var cert = new Certificate()) 并将此对象添加到列表中customer.CertificatesAsInvestor.Add(cert)然后调用SaveChanges()时,新证书不会存储在数据库中。

为什么会这样,我必须做些什么才能让它发挥作用?

客户等级:

public partial class Customer
{
    public Customer()
    {
        this.Deceased = false;
        this.CertificatesAsInvestor = new HashSet<Certificate>();
        this.CertificatesAsBeneficiary = new HashSet<Certificate>();
        this.BankAccounts = new HashSet<BankAccount>();
        this.Notes = new HashSet<Note>();
        this.Documents = new HashSet<Document>();
        this.Name = new PersonName();
    }

    public int Id { get; set; }
    public string Code { get; set; }
    public string CompanyName { get; set; }
    public string EmailAddress { get; set; }
    public System.DateTime BirthDate { get; set; }
    public string BSNNo { get; set; }
    public string IdCardNo { get; set; }
    public bool Deceased { get; set; }
    public Kompas.Bas.Gender Gender { get; set; }
    public Kompas.Bas.Title Title { get; set; }
    public string DayPhone { get; set; }
    public string OtherPhone { get; set; }
    public Kompas.Bas.CustomerStatus Status { get; set; }

    public PersonName Name { get; set; }

    public virtual Address Address { get; set; }
    public virtual ICollection<Certificate> CertificatesAsInvestor { get; set; }
    public virtual ICollection<Certificate> CertificatesAsBeneficiary { get; set; }
    public virtual Address PostalAddress { get; set; }
    public virtual ICollection<BankAccount> BankAccounts { get; set; }
    public virtual ICollection<Note> Notes { get; set; }
    public virtual ICollection<Document> Documents { get; set; }
}

证书:

public partial class Certificate
{
    public Certificate()
    {
        this.Transactions = new HashSet<Transaction>();
        this.Notes = new HashSet<Note>();
        this.Clicks = new HashSet<Click>();
        this.ParticipationCalculations = new HashSet<ParticipationCalculation>();
    }

    public int Id { get; set; }
    public int CertificateNo { get; set; }
    public decimal NominalFee { get; set; }
    public bool IsSigned { get; set; }
    public System.DateTime DateIn { get; set; }
    public Nullable<System.DateTime> ReturnDate { get; set; }
    public Nullable<System.DateTime> OrderDate { get; set; }
    public Nullable<System.DateTime> DateStop { get; set; }
    public Kompas.Bas.Paymethod Paymethod { get; set; }
    public Kompas.Bas.CertificateStatus Status { get; set; }
    public Nullable<int> DexContractNumber { get; set; }
    public Nullable<int> CollectionId { get; set; }
    public Nullable<System.DateTime> FinalDateMin { get; set; }
    public Nullable<System.DateTime> FinalDateMax { get; set; }
    public bool Gift { get; set; }
    public decimal PurchaseRate { get; set; }
    public decimal PurchaseRateDiscount { get; set; }
    public Nullable<System.DateTime> PayStopDate { get; set; }
    public decimal GuaranteeValue { get; set; }
    public int PaidTermCount { get; set; }
    public decimal DepositNominal { get; set; }
    public string SecondName { get; set; }
    public Nullable<System.DateTime> SecondBirthDate { get; set; }

    public virtual Customer InvestingCustomer { get; set; }
    public virtual Customer BeneficiaryCustomer { get; set; }
    public virtual InvestorRole InvestorRole { get; set; }
    public virtual Product Product { get; set; }
    public virtual BankAccount CollectionBankAccount { get; set; }
    public virtual BankAccount PaymentBankAccount { get; set; }
    public virtual Origin Origin { get; set; }
    public virtual ICollection<Transaction> Transactions { get; set; }
    public virtual ICollection<Note> Notes { get; set; }
    public virtual ICollection<Click> Clicks { get; set; }
    public virtual ICollection<ParticipationCalculation> ParticipationCalculations { get; set; }
}
4

0 回答 0