Note that there are some explanatory texts on larger screens.

plurals
  1. POEntity Framework mapping to existing FoxPro free tables
    primarykey
    data
    text
    <p>I am working with a pre-existing set of FoxPro tables. One table in specific </p> <pre><code>public class Charges { public string Bill_Num { get; set; } public string Type { get; set; } public string Chargeid { get; set; } public string Postid { get; set; } public DateTime Createdt { get; set; } public DateTime Modifydt { get; set; } public string Createtm { get; set; } public string Modifytm { get; set; } { </code></pre> <p>seems to be TPH. The discriminator is the <code>Type</code> field (<code>C</code> or <code>P</code>), so I am mapping along these lines:</p> <pre><code>public abstract class LineItem { public string Bill_num { get; set; } public string Type { get; set; } public DateTime Createdt { get; set; } public DateTime Modifydt { get; set; } public string Createtm { get; set; } public string Modifytm { get; set; } } public class LineItemMap : EntityTypeConfiguration&lt;LineItem&gt; { public LineItemMap() { this.Map&lt;Charge&gt;(m =&gt; m.Requires("Type").HasValue("C")); this.Map&lt;Posting&gt;(m =&gt; m.Requires("Type").HasValue("P")); this.ToTable("Charges"); this.Property(t =&gt; t.Bill_Num).HasColumnName("Bill_Num"); this.Property(t =&gt; t.Type).HasColumnName("Type"); this.Property(t =&gt; t.Createdt).HasColumnName("Createdt"); this.Property(t =&gt; t.Modifydt).HasColumnName("Modifydt"); this.Property(t =&gt; t.Createtm).HasColumnName("Createtm"); this.Property(t =&gt; t.Modifytm).HasColumnName("Modifytm"); } } </code></pre> <p>and</p> <pre><code>public class Charge : LineItem { public string Chargeid { get; set; } } public class ChargeMap : EntityTypeConfiguration&lt;Charge&gt; { public ChargeMap() { this.HasKey(t =&gt; t.Chargeid); this.Property(t =&gt; t.Chargeid) this.ToTable("Charges"); this.Property(t =&gt; t.Chargeid).HasColumnName("Chargeid"); } } </code></pre> <p>and</p> <pre><code>public class Posting : LineItem { public string Postid { get; set; } } public class PostingMap : EntityTypeConfiguration&lt;Posting&gt; { public PostingMap() { this.HasKey(t =&gt; t.Postid); this.Property(t =&gt; t.Postid) this.ToTable("Charges"); this.Property(t =&gt; t.Postid).HasColumnName("Postid"); } } </code></pre> <p>If I do this, <code>LineItem</code> is missing a simple primary key. I think a composite key of <code>{ t.Bill_num, t.Createdt, t.Createtm }</code> would be unique, but I am not sure if EF and/or the FoxPro provider will like that.</p> <p>The second problem is there seems to be a subclass of both <code>Charges</code> and <code>Postings</code> that encompasses voiding entries (aka deletes) and does not appear to be assigned a <code>Chargeid</code>/<code>Postid</code>, but it does have a discriminator so they will be derived types with a <code>null</code> or <code>" "</code> key value.</p> <p>Am I missing something, or am I on the right track with my mappings/key assignments?</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.
    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