Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I make heavy use of tables (with default values) in DB of the form </p> <pre><code>CREATE TABLE [dbo].[CommunicationPreferences] ( [ID] smallint NOT NULL, [SystemName] nvarchar(50) NOT NULL, [Description] nvarchar(200) NOT NULL, ) </code></pre> <p>And I drive my EF4 entities from the DB.</p> <p>N.B. I use no views, SPROCS or SQL functions, no complex EF types, just direct table to entity mapping. Then extend my entity partial classes to add additional functionality to keep things DRY. </p> <p>For Enums I have a simple T4 template, which I hand a list of tables (of the form above), the .tt file gets fired off whenever I update the EF model from the DB (or if I need to on demand), it grabs the data, and builds Enums e.g. </p> <pre><code>/// &lt;summary&gt; /// Enums For The dbo Schema /// &lt;/summary&gt; public enum CommunicationPreferencesList : short { /// &lt;summary&gt; /// HTML Emails /// &lt;/summary&gt; [EnumTextValue(@"HTML Emails")] HTMLEmail = 1, /// &lt;summary&gt; /// Plain Text Emails /// &lt;/summary&gt; [EnumTextValue(@"Plain Text Emails")] PlainEmail = 2, /// &lt;summary&gt; /// Mobile Telephone /// &lt;/summary&gt; [EnumTextValue(@"Mobile Telephone")] Mobile = 3, /// &lt;summary&gt; /// Landline Telephone /// &lt;/summary&gt; [EnumTextValue(@"Landline Telephone")] Landline = 4, /// &lt;summary&gt; /// SMS /// &lt;/summary&gt; [EnumTextValue(@"SMS")] SMS = 5, } </code></pre> <p>Then when I am dealing with an FK ID column / Property on some entity e.g. </p> <pre><code>Users.CommunicationPreferenceID </code></pre> <p>I simply cast either the ID or the enum for the comparison. e.g.</p> <pre><code>CommunicationPreferencesList usersPreference = (CommunicationPreferencesList)currentUser.CommunicationPreferenceID; if(usersPreference == CommunicationPreferencesList.SMS) { //send SMS } else if(usersPreference == CommunicationPreferencesList.Mobile) { //ring the phone } </code></pre> <p>I then have some simple helpers to e.g. give the EnumTextValue from an enum instance e.g. </p> <pre><code>string chosenMethod = EntityHelper.GetEnumTextValue(CommunicationPreferencesList.Mobile); =&gt; "Mobile Telephone" </code></pre> <p>I find this simple, hassle free, transparent, easy to use, and for my purposes it works a treat and I am happy. I don't see the need to totally mask the numeric value in the DB / entity from the consuming code, I am quite happy to cast one or other of the values, and end up with pretty clean readable code, plus the nice little extra of the EnumTextValue which is generated from the [Description] field in the DB. </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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