I have a table of "Statements" that is related to both :
- a table of "Transactions" (with a foreign key on IdStatement)
- a table of "SpecificTransactions". The class "SpecificTransaction" inherits from the table "Transaction"
This is the existing code First Model :
Table Statement
[Serializable] [Table("Statement", Schema = "dbo")] public class Statement { public Statement() { this.Transactions = new List<Transaction>(); this.SpecificTransactions = new List<SpecificTransaction>(); } [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int IdStatement { get; set; } public List<Transaction> Transactions { get; set; } public List<SpecificTransaction> SpecificTransactions { get; set; } [... Other properties ...] }Table Transaction
[Serializable] [Table("Transaction", Schema = "dbo")] public class Transaction { [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int IdTransaction { get; set; } [ForeignKey("Statement")] public Nullable<int> IdStatement { get; set; } [... Other properties ...] }Table SpecificTransaction (inherits from Transaction)
[Serializable] [Table("SpecificTransaction", Schema = "dbo")] public class SpecificTransaction : Transaction { [StringLength(255)] public string UniqueValue { get; set; } [StringLength(50)] public string Status { get; set; } [StringLength(50)] public string Hash { get; set; } [... Other properties ...] }
When the database is being created, an unwanted field (i.e column) is added on my table SpecificTransaction, called "Statement_IdStatement".
When I try to add my Statement containing SpecificTransactions, none of the following columns :
- Table Transaction > Column IdStatement
- Table SpecificTransaction > Column Statement_IdStatement
Is being populated by the IdStatement, I have to add the Id afterwards.
Furthermore, when I assign the "IdStatement" on my table "SpecificTransaction", only the "Statement_IdStatement" column is filled, and not the "IdStatement" of my table Statement.
Is there a way to :
avoid the creation of the column "Statement_IdStatement" and keeping my EF Code First class that way ? (or at least, have no change on the tables Statement and Transaction)
When I add my Statements containing SpecificTransactions and I saveChanges, the column "Transaction" > "IdStatement" is automatically populated ?
Thanks in advance.