Note that there are some explanatory texts on larger screens.

plurals
  1. PODDD: Enum like entities
    text
    copied!<p>I have the following DB model:</p> <pre><code>**Person table** ID | Name | StateId ------------------------------ 1 Joe 1 2 Peter 1 3 John 2 **State table** ID | Desc ------------------------------ 1 Working 2 Vacation </code></pre> <p>and domain model would be (simplified):</p> <pre><code>public class Person { public int Id { get; } public string Name { get; set; } public State State { get; set; } } public class State { private int id; public string Name { get; set; } } </code></pre> <p>The state might be used in the domain logic e.g.:</p> <pre><code>if(person.State == State.Working) // some logic </code></pre> <p>So from my understanding, the State acts like a value object which is used for domain logic checks. But it also needs to be present in the DB model to represent a clean ERM.</p> <p>So state might be extended to:</p> <pre><code>public class State { private int id; public string Name { get; set; } public static State New {get {return new State([hardCodedIdHere?], [hardCodeNameHere?]);}} } </code></pre> <p>But using this approach the name of the state would be hardcoded into the domain. </p> <p>Do you know what I mean? Is there a standard approach for such a thing? From my point of view what I am trying to do is using an object (which is persisted from the ERM design perspective) as a sort of value object within my domain. What do you think?</p> <p><strong>Question update:</strong> Probably my question wasn't clear enough.</p> <p>What I need to know is, how I would use an entity (like the State example) that is stored in a database within my domain logic. To avoid things like:</p> <pre><code> if(person.State.Id == State.Working.Id) // some logic </code></pre> <p>or</p> <pre><code>if(person.State.Id == WORKING_ID) // some logic </code></pre>
 

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