Created
July 20, 2012 08:21
-
-
Save danielwertheim/3149566 to your computer and use it in GitHub Desktop.
Rough key-value store
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| var db = "data source=.;initial catalog=fff;integrated security=true;".CreateSql2012Db(); | |
| db.EnsureNewDatabase(); | |
| var mdoc = new Doc { Name = "MD doc" }; | |
| mdoc.Set("Substitute", "Ibuprofen"); | |
| db.UseOnceTo().Insert(mdoc); | |
| var refetched = db.UseOnceTo().Query<Doc>().Where(d => d.Attributes.QxAny(a => a.Name == "Substitute" && a.Value == "Ibuprofen")).Single(); | |
| Console.WriteLine(refetched.Get("Substitute")); | |
| } | |
| } | |
| public class Doc | |
| { | |
| private Dictionary<string, DocAttribute> _attributes = new Dictionary<string, DocAttribute>(); | |
| public Guid StructureId { get; set; } | |
| public string Name { get; set; } | |
| public IEnumerable<DocAttribute> Attributes | |
| { | |
| get { return _attributes.Values; } | |
| set { _attributes = value.ToDictionary(v => v.Name); } | |
| } | |
| public void Set(string name, string value) | |
| { | |
| _attributes[name] = new DocAttribute{Name = name, Value = value}; | |
| } | |
| public string Get(string name) | |
| { | |
| return _attributes.ContainsKey(name) ? _attributes[name].Value : null; | |
| } | |
| } | |
| public class DocAttribute | |
| { | |
| public string Name { get; set; } | |
| public string Value { get; set; } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment