Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple tables containing one entity in Entity Framework
    primarykey
    data
    text
    <p>I am working on a system that sells products. This system has products, with subclasses for every producttype. </p> <pre><code>public abstract class Product { public int ProductId { get; set; } public string naam { get; set; } public string barcode { get; set; } } public class Card :Product { [Display(Name = "Cardnumber")] public int nummer { get; set; } public Kaliber kaliber { get; set; } } </code></pre> <p>Furthermore, i want to keep a history of all the products i sold with all the data that was correct at that moment.</p> <pre><code> public class Transaction { public int transactionId { get; set; } public Member member { get; set; } public virtual ICollection&lt;Product&gt; producten { get; set; } public double totaalprijs { get; set; } public DateTime tijdstip { get; set; } public string kantoorMedewerker { get; set; } } </code></pre> <p>The problem is, that entity now makes a FK in Product to Transaction. That's not what i want. I want a seperate table for each of them; a Products table and a SoldProducts table. I already tried this in my productContext:</p> <pre><code>public DbSet&lt;Product&gt; producten { get; set; } public DbSet&lt;Product&gt; uitgifte_producten { get; set; } </code></pre> <p>That's not possible, because EF doesn't allow multiple object sets per type . This seems like something trivial, but i can't figure it out. Making two classes, one Product and one Soldproduct, with both of having subclasses of the producttypes, seems rather ugly. I tried it, but VS2012 complains that it can't converty Product to SoldProduct.</p> <p>What seems to be a good idea to do this in C#, .net 4.0 and EF?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload