-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Repository Pattern
mbdavid edited this page Mar 14, 2015
·
4 revisions
LiteDB architeture is ideal to work in repository pattern data access. You can write a class that inheriths LiteDatabase
and add your collections as properties:
See below an example to how implement
public class MyDB : LiteDatabase
{
public MyDB()
: this (@"C:\Temp\mydatabase.db")
{
}
}
public class CustomerRepository : LiteCollection<Customer>
{
public
}
private LiteCollection<Customer> _customers;
public LiteCollection<Customer> Customers
{
get { return _customers ?? (_customers = this.GetCollection<Customer>("customers")); }
}
private LiteCollection<Order> _orders;
public LiteCollection<Order> Orders
{
get { return _orders ?? (_orders = this.GetCollection<Order>("orders")); }
}
}
// later...
using(var db = new MyDB())
{
var cust = new Customer { Id = 123, Name = "John Doe" };
db.Customers.Insert(cust);
db.Customers.Delete(123);
}
Data Modeling
- Data Structure
- BsonDocument
- Object Mapping
- Relationships with Document References
- Collections
- FileStorage
Index
Query
Database
Version 4 changes
Shell