百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
F

FileContextCore

> 数据库
开源

FileContextCore 是一个用于 Entity Framework Core 的"数据库"提供程序,它增加了将信息存储在文件中的功能,而不再局限于数据库。

179 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

FileContextCore 是一个用于 Entity Framework Core 的"数据库"提供程序,它增加了将信息存储在文件中的功能,而不再局限于数据库。

FileContextCore

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)

Advantages

  • 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!

Install

https://www.nuget.org/packages/FileContextCore/

PM > Install-Package FileContextCore

Configure EF Core

Configure in DI-Service configuration

In your Startup.cs use this:

cs
public void ConfigureServices(IServiceCollection services)
{
    ...
    services.AddDbContext(options => options.UseFileContextDatabase());
    ...
}

or

Override OnConfiguring method

You can also override the OnConfiguring method of your DbContext to apply the settings:

cs
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    optionsBuilder.UseFileContextDatabase();
}

Example

For a simple example check out: Example

You can also play around with this example on dotnetfiddle.net: Demo

Configuration

By default the extension uses JSON-serialization and the DefaultFileManager

You can use a different serializer to support other serialization methods.

Available Serializer

XMLSerializer

Serializes data using System.XML

cs
optionsBuilder.UseFileContextDatabase();

CSVSerializer

Serializes data using CsvHelper (https://joshclose.github.io/CsvHelper/)

cs
optionsBuilder.UseFileContextDatabase();

JSONSerializer

Serializes data using Newtonsoft Json.NET (http://www.newtonsoft.com/json)

cs
optionsBuilder.UseFileContextDatabase();

or just

optionsBuilder.UseFileContextDatabase();

BSONSerializer

Serializes data to bson using Newtonsoft Json.NET (http://www.newtonsoft.com/json)

cs
optionsBuilder.UseFileContextDatabase();

EXCELSerializer

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)

cs
optionsBuilder.UseFileContextDatabase();

If you want to secure the excel file with a password use:

cs
optionsBuilder.UseFileContextDatabase(password: "");

To run on Linux-Systems

bash
sudo apt-get update
sudo apt-get install libgdiplus

File Manager

The file manager controls how the files are stored.

DefaultFileManager

The default file manager just creates normal files.

cs
optionsBuilder.UseFileContextDatabase();

EncryptedFileManager

The encrypted file manager encrypts the files with a password.

cs
optionsBuilder.UseFileContextDatabase(password: "");

Custom file-location

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.

cs
optionsBuilder.UseFileContextDatabase(location: @"C:\Users\mjanatzek\Documents\Projects\test");

Multiple Databases

If nothing 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.

cs
optionsBuilder.UseFileContextDatabase(databasename: "database");

Custom provider

You can create custom serializer, file manager and store manager if you want.

If you want to create a custom serializer implement the interface ISerializer.

If you want to control storing of data implement interface IFileManager.

If you want to create a store manager that does both implement IStoreManager.

After adding a custom provider you have to add it as a transient dependency in the dependency injection.

Feel free to create a PR with your new provider and I'll add it to FileContextCore.

Version compability

FileContext Version EF Core Version
3.4.* 3.1.0
3.3.* 3.0.0
3.2.* 3.0.0
3.0.1/3.0.0/2.2.6 2.2.6
2.2.0 2.2.0

Custom table/file name

It seems that EF Core currently does not support to define a custom table name using annotations on models. Use the OnModelCreating-method to define a custom table name.

csharp
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity()
        .ToTable("custom_user_table");
}

This will store the data in a file called custom_user_table.json for example.

Author

Morris Janatzek (morrisjdev)

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C#csvdatabasedbcontextentity-framework

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库