Note that there are some explanatory texts on larger screens.

plurals
  1. POEntityFramework Code First approach for mapping convoluted legacy database linking table?
    primarykey
    data
    text
    <p>I am working with a legacy database that cannot have its structure changed (at least not yet), and it has something like this:</p> <pre><code>**Profile**: profile_id first_name last_name **OneBigLookupTableToRuleThemAll**: lookup_id (PK) category_id (PK) (refers to a recrod in a OneBigCategoryTableToRuleThemAll) description (basically a label) **ProfileProperties**: property_key (PK GUID) profile_id lookup_id UNIQUE constraint on profile_id, lookup_id </code></pre> <p>As an example of two categories:</p> <pre><code>Degrees (MD, PhD, MS, MPH, etc) -- cat_id 1, for example Job Responsibilities (Statistician, Medical Doctor, Epidemiologist, etc) -- cat_id 2 </code></pre> <p>So, in the Lookup table, we end up with stuff like this:</p> <pre><code>lookup_id, cat_id, description 1 , 1 , MD 2 , 1 , PhD 3 , 1 , MS 4 , 1 , MPH 5 , 2 , Statistician 6 , 2 , Medical Doctor 7 , 2 , Epidemiologist </code></pre> <p>Thus, in the ProfileProperties table we end up with stuff like:</p> <pre><code>property_key, profile_id, lookup_id some guid , 1 , 1 -- MD degree some guid , 1 , 4 -- MPH degree some guid , 1 , 6 -- Medical Doctor </code></pre> <p>I would like to have an entity like this:</p> <pre><code>public class Profile { public int ProfileId { get; } public string FirstName { get; set; } public string LastName { get; set; } public ICollection&lt;JobResponsibility&gt; JobResponsibilities { get; set; } public ICollection&lt;Degree&gt; Degrees { get; set; } } public class JobResponsibility { public int Id { get; set; } public string Description { get; set; } } public class Degree { public int Id { get; set; } public string Description { get; set; } } </code></pre> <p>-- Actually, in the setters of the Id, I would like to constrain the value to one of the actual values that is in the database, though I'm not sure I'd go to full blown Enum-type support (and I know code first does not support that yet)</p> <p>I believe one of the EntityFramework mapping scenarios should be able to handle this, but I'm having trouble figuring out what I need to do to get this to work.</p> <p>Anyone have any tips or resources I can read up on this kind of scenario? I'm thinking it's actually going to end up very basic, but I'm new to EF.</p> <p>Thank you, Josh</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