A document database in the most literal case.
This document storage could be used to create quick prototypes without the need of connecting to an actual database. Lith.DocStore provides interfaces that allow you to create physical data files which can be JSON, XML or anything you can serialize.
The idea behind this is that you can run unit tests against models and logic without commiting to a database or having a connection.
- Models can live in a seperate project, which reduces the need for DTO project/objects.
- No setup apart from Creating your models
- Can be used instead of having the need to create a database when building a new project
- Any other benefits I couldn't think of.
nuget: install-package lith.docstore
- Create Models
public abstract class BaseRecord : IStoreable
{
public Guid ID { get; set; }
public DateTime DateCreated { get; set; }
public bool IsDeleted { get; set; }
}
public class Transaction : BaseRecord
{
public bool IsExpense { get; set; }
public Shop Shop { get; set; }
public decimal Amount { get; set; }
public DateTime Date { get; set; }
}
- Setup Context
public class ModelsContext : StoreContext
{
public ModelsContext()
: base(new JSONModelHelper())
{
}
public ItemSet<Shop> Shops { get; set; }
public ItemSet<Transaction> Transactions { get; set; }
public ItemSet<Summary> Summaries { get; set; }
}
- Add Record
var shopA = new Shop
{
Category = "XX",
Name = "SupermarketX"
};
using (var ctx = new ModelsContext())
{
ctx.Shops.Add(shopA);
ctx.Save();
}
- Query Record
using (var ctx = new ModelsContext())
{
var results = from a in ctx.Shops
where a.Name == "SupermarketX"
&& a.Category == "XX"
select a;
}
- Find and Update Record
using(var ctx = new ModelsContext())
{
var item = ctx.Shops.Find(id);
item.Name = "DEF";
ctx.Save();
}
- Have a cold one ;)