Skip to content

Instantly share code, notes, and snippets.

@tkellogg
Created March 23, 2012 03:38
Show Gist options
  • Save tkellogg/2166519 to your computer and use it in GitHub Desktop.
Save tkellogg/2166519 to your computer and use it in GitHub Desktop.
Why Object IDs & Primary Keys Are Implementation Details
public class Word {
public int Id { get; set; }
public string Name { get; set; }
public IList<Definition> Definitions { get; private set; }
}
public class Definition {
public int Id { get; set; }
public int WordId { get; set; }
public string Text { get; set; }
public string Example { get; set; }
}
public class Word {
private object Id { get; set; }
public string Name { get; set; }
public IList<Definition> Definitions { get; private set; }
public void Add(Definition definition) {
if (definition == null) throw new ArgumentNullException();
Definitions.Add(definition);
}
}
public class Definition {
public Definition(string text, string example) {
Text = text;
Example = example;
}
private object Id { get; set; }
public string Text { get; private set; }
public string Example { get; private set; }
}
{
"_id": "09823bcf7de88c",
"name": "LOL",
"definitions": [
{
"text": "Laugh Out Loud"
"example": "I can't wait for the wedding. LOL"
},
{
"text": "Lots Of Love",
"example": "I don't have the heart to let my mom know that LOL doesn't actually mean Lots Of Love"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment