Skip to content

Instantly share code, notes, and snippets.

@danielwertheim
Created July 20, 2012 08:21
Show Gist options
  • Select an option

  • Save danielwertheim/3149566 to your computer and use it in GitHub Desktop.

Select an option

Save danielwertheim/3149566 to your computer and use it in GitHub Desktop.
Rough key-value store
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