NMemory Overview
Description
NMemory is a lightweight non-persistent in-memory relational database engine that is purely written in C# and can be hosted by .NET applications. It supports traditional database features;
- Indexes
- Foreign Key Relations
- Transaction Handling and Isolation
- Stored Procedures
- Query Optimization
Installing & Upgrading Download the NuGet Package
NMemory library provides a class called Database which represents an in-memory database instance.
public class MyDatabase : Database { public MyDatabase() { var members = this.Tables.Create<Member, int>(x => x.Id); var groups = base.Tables.Create<Group, int>(g => g.Id); this.Members = members; this.Groups = groups; RelationOptions options = new RelationOptions( cascadedDeletion: true); var peopleGroupIdIndex = members.CreateIndex( new RedBlackTreeIndexFactory(), p => p.GroupId); this.Tables.CreateRelation( groups.PrimaryKeyIndex, peopleGroupIdIndex, x => x ?? -1, x => x, options); } public ITable<Member> Members { get; private set; } public ITable<Group> Groups { get; private set; } }
Once the in-memory database is defined, create a database instance and insert some data into the in-memory database.
MyDatabase myDatabase = new MyDatabase(); myDatabase.Groups.Insert(new Group() { Id = 1}); myDatabase.Groups.Insert(new Group() { Id = 2}); myDatabase.Members.Insert(new Member() { Id = 1, GroupId = 1, Name = "It's Member_1" }); myDatabase.Members.Insert(new Member() { Id = 2, Name = "It's Member_2" });
Currently, it just serves as the core component of the Effort library. However, developer interest and contribution could make it a more robust engine that might serve well in a wide range of scenarios.
Contribute
The best way to contribute is by spreading the word about the library:
- Blog it
- Comment it
- Fork it
- Star it
- Share it
- A HUGE THANKS for your help.