FileContextCore is a "Database"-Provider for Entity Framework Core and adds the ability to store information in files. It enables fast developments because of the advantage of just copy, edit and delete files.
This framework bases on the idea of FileContext by DevMentor (https://github.com/pmizel/DevMentor.Context.FileContext)
- No database needed
- easy configuration
- rapid data-modelling, -modification
- share data through version-control
- supports all serializable .NET types
- integrates seamlessly into EF Core
- different serializer supported (XML, JSON, CSV, Excel)
- supports encryption
- supports relations
- supports multiple databases
!This extension is not intended to be used in production systems!
https://www.nuget.org/packages/FileContextCore/
PM > Install-Package FileContextCore
In your Startup.cs
use this:
public void ConfigureServices(IServiceCollection services)
{
...
services.AddDbContext<Context>(options => options.UseFileContext());
...
}
You can also override the OnConfiguring
method of your DbContext to apply the settings:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseFileContext();
}
For a simple example check out: Example
You can also play around with this example on dotnetfiddle.net: Demo
By default the extension uses JSON
-serialization and the DefaultFileManager
You can use a different serializer to support other serialization methods.
Serializes data using System.XML
optionsBuilder.UseFileContext("xml");
Serializes data using CsvHelper (https://joshclose.github.io/CsvHelper/)
optionsBuilder.UseFileContext("csv");
Serializes data using Newtonsoft Json.NET (http://www.newtonsoft.com/json)
optionsBuilder.UseFileContext("json");
or just
optionsBuilder.UseFileContext();
Serializes data to bson using Newtonsoft Json.NET (http://www.newtonsoft.com/json)
optionsBuilder.UseFileContext("bson");
Saves files into an .xlsx-file and enables the quick editing of the data using Excel
Uses EEPlus implementation for .Net Core (https://github.com/VahidN/EPPlus.Core)
optionsBuilder.UseFileContext("excel");
If you want to secure the excel file with a password use:
optionsBuilder.UseFileContext("excel:<password>");
To run on Linux-Systems
sudo apt-get update
sudo apt-get install libgdiplus
The file manager controls how the files are stored.
The default file manager just creates normal files.
optionsBuilder.UseFileContext("json", "default");
The encrypted file manager encrypts the files with a password.
optionsBuilder.UseFileContext("json", "encrypted:<password>");
By default the files are stored in a subfolder of your running application called appdata
.
If you want to control this behavior you can also use define a custom location.
optionsBuilder.UseFileContext(location: @"C:\Users\mjanatzek\Documents\Projects\test");
If noting is configured all files of your application will be stored in a flat folder. You can optionally define a name for your database and all the corresponding data will saved in a subfolder. So you are able to use FileContext with multiple DbContext-configurations.
optionsBuilder.UseFileContext(databasename: "database");