Skip to content

Commit 1534203

Browse files
committed
updated readme
updated demo
1 parent aee913b commit 1534203

File tree

3 files changed

+60
-46
lines changed

3 files changed

+60
-46
lines changed

Example/Data/Context.cs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
using System.IO;
2-
using Microsoft.EntityFrameworkCore;
3-
using Example.Data.Entities;
1+
using Example.Data.Entities;
42
using FileContextCore;
5-
using FileContextCore.FileManager;
6-
using FileContextCore.Serializer;
3+
using Microsoft.EntityFrameworkCore;
74

85
namespace Example.Data
96
{
@@ -23,28 +20,28 @@ public class Context : DbContext
2320

2421
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
2522
{
26-
//Default: JSON-Serialize
27-
// optionsBuilder.UseFileContextDatabase();
23+
//Default: JSON-Serializer
24+
optionsBuilder.UseFileContextDatabase();
2825

2926
// optionsBuilder.UseFileContextDatabase<JSONSerializer, DefaultFileManager>();
3027

31-
//optionsBuilder.UseFileContextDatabase("bson");
28+
// optionsBuilder.UseFileContextDatabase<BSONSerializer, DefaultFileManager>();
3229

3330
//JSON-Serialize + simple Encryption
34-
//optionsBuilder.UseFileContextDatabase("json", "encrypted");
31+
// optionsBuilder.UseFileContextDatabase<JSONSerializer, EncryptedFileManager>();
3532

3633
//XML
37-
//optionsBuilder.UseFileContextDatabase("xml");
38-
//optionsBuilder.UseFileContextDatabase("xml", "private");
34+
// optionsBuilder.UseFileContextDatabase<XMLSerializer, DefaultFileManager>();
35+
// optionsBuilder.UseFileContextDatabase<XMLSerializer, PrivateFileManager>();
3936

4037
//CSV
41-
//optionsBuilder.UseFileContextDatabase("csv", location: @"D:\t");
38+
// optionsBuilder.UseFileContextDatabase<CSVSerializer, DefaultFileManager>();
4239

43-
//Excel
44-
//optionsBuilder.UseFileContextDatabase("excel", databaseName: "test");
40+
//Custom location
41+
// optionsBuilder.UseFileContextDatabase(location: @"D:\t");
4542

46-
//ConnectionString
47-
//optionsBuilder.UseFileContextDatabaseConnectionString("SeriAlizer=xml;databasenaMe=Test");
43+
//Excel
44+
// optionsBuilder.UseFileContextDatabase<EXCELStoreManager>(databaseName: "test");
4845
}
4946

5047
protected override void OnModelCreating(ModelBuilder modelBuilder)

FileContextCore/StoreManager/EXCELStoreManager.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,8 @@ public void Initialize(IFileContextScopedOptions options, IEntityType entityType
6565
{
6666
_package = _packages[options.DatabaseName];
6767
}
68-
69-
string[] nameParts = entityType.Name.Split('.');
70-
string name = nameParts[nameParts.Length - 1];
71-
68+
69+
string name = entityType.GetTableName();
7270
_worksheet = _package.Workbook.Worksheets[name];
7371

7472
if (_worksheet == null)

README.md

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ This framework bases on the idea of FileContext by DevMentor ([https://github.co
88
## Advantages
99

1010
- No database needed
11-
- easy configuration
12-
- rapid data-modelling, -modification
13-
- share data through version-control
14-
- supports all serializable .NET types
15-
- integrates seamlessly into EF Core
16-
- different serializer supported (XML, JSON, CSV, Excel)
17-
- supports encryption
18-
- supports relations
19-
- supports multiple databases
11+
- Easy configuration
12+
- Rapid data-modelling, -modification
13+
- Share data through version-control
14+
- Supports all serializable .NET types
15+
- Integrates seamlessly into EF Core
16+
- Different serializer supported (XML, JSON, CSV, Excel)
17+
- Supports encryption
18+
- Supports relations
19+
- Supports multiple databases
2020

2121
!This extension is not intended to be used in production systems!
2222

@@ -75,23 +75,23 @@ You can use a different serializer to support other serialization methods.
7575
Serializes data using System.XML
7676

7777
```cs
78-
optionsBuilder.UseFileContextDatabase("xml");
78+
optionsBuilder.UseFileContextDatabase<XMLSerializer, DefaultFileManager>();
7979
```
8080

8181
### CSVSerializer
8282

8383
Serializes data using CsvHelper ([https://joshclose.github.io/CsvHelper/](https://joshclose.github.io/CsvHelper/))
8484

8585
```cs
86-
optionsBuilder.UseFileContextDatabase("csv");
86+
optionsBuilder.UseFileContextDatabase<CSVSerializer, DefaultFileManager>();
8787
```
8888

8989
### JSONSerializer
9090

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

9393
```cs
94-
optionsBuilder.UseFileContextDatabase("json");
94+
optionsBuilder.UseFileContextDatabase<JSONSerializer, DefaultFileManager>();
9595
```
9696
or just
9797
```
@@ -103,7 +103,7 @@ optionsBuilder.UseFileContextDatabase();
103103
Serializes data to bson using Newtonsoft Json.NET ([http://www.newtonsoft.com/json](http://www.newtonsoft.com/json))
104104

105105
```cs
106-
optionsBuilder.UseFileContextDatabase("bson");
106+
optionsBuilder.UseFileContextDatabase<BSONSerializer, DefaultFileManager>();
107107
```
108108

109109
### EXCELSerializer
@@ -113,12 +113,12 @@ Saves files into an .xlsx-file and enables the quick editing of the data using E
113113
Uses [EEPlus](http://epplus.codeplex.com/documentation) implementation for .Net Core ([https://github.com/VahidN/EPPlus.Core](https://github.com/VahidN/EPPlus.Core))
114114

115115
```cs
116-
optionsBuilder.UseFileContextDatabase("excel");
116+
optionsBuilder.UseFileContextDatabase<EXCELStoreManager>();
117117
```
118118

119119
If you want to secure the excel file with a password use:
120120
```cs
121-
optionsBuilder.UseFileContextDatabase("excel:<password>");
121+
optionsBuilder.UseFileContextDatabase<EXCELStoreManager>(password: "<password>");
122122
```
123123

124124
To run on Linux-Systems
@@ -136,26 +136,17 @@ The file manager controls how the files are stored.
136136
The default file manager just creates normal files.
137137

138138
```cs
139-
optionsBuilder.UseFileContextDatabase("json", "default");
139+
optionsBuilder.UseFileContextDatabase<JSONSerializer, DefaultFileManager>();
140140
```
141141

142142
### EncryptedFileManager
143143

144144
The encrypted file manager encrypts the files with a password.
145145

146146
```cs
147-
optionsBuilder.UseFileContextDatabase("json", "encrypted:<password>");
147+
optionsBuilder.UseFileContextDatabase<JSONSerializer, EncryptedFileManager>(password: "<password>");
148148
```
149149

150-
## Configuration string
151-
152-
If you want to define the options of file context in a single string you can use the default connection string syntax of databases.
153-
154-
```css
155-
optionsBuilder.UseFileContextDatabaseConnectionString("serializer=xml;databasename=Test;location:test;filemanager:default");
156-
```
157-
158-
159150
## Custom file-location
160151

161152
By default the files are stored in a subfolder of your running application called `appdata`.
@@ -175,14 +166,42 @@ So you are able to use FileContext with multiple DbContext-configurations.
175166
optionsBuilder.UseFileContextDatabase(databasename: "database");
176167
```
177168

169+
## Custom provider
170+
171+
You can create custom serializer, file manager and store manager if you want.
172+
173+
If you want to create a custom serializer implement the interface `ISerializer`.
174+
175+
If you want to control storing of data implement interface `IFileManager`.
176+
177+
If you want to create a store manager that does both implement `IStoreManager`.
178+
179+
Feel free to create a PR with your new provider and I'll add it to FileContextCore.
180+
178181
## Version compability
179182

180183
| FileContext Version | EF Core Version |
181184
|---------------------|-----------------|
185+
| 3.3.* | 3.0.0 |
182186
| 3.2.* | 3.0.0 |
183187
| 3.0.1/3.0.0/2.2.6 | 2.2.6 |
184188
| 2.2.0 | 2.2.0 |
185189

190+
## Custom table/file name
191+
192+
It seems that EF Core currently does not support to define a custom table name using annotations on models.
193+
Use the `OnModelCreating`-method to define a custom table name.
194+
195+
````c#
196+
protected override void OnModelCreating(ModelBuilder modelBuilder)
197+
{
198+
modelBuilder.Entity<User>()
199+
.ToTable("custom_user_table");
200+
}
201+
````
202+
203+
This will store the data in a file called `custom_user_table.json` for example.
204+
186205
## Author
187206

188207
[Morris Janatzek](http://morrisj.net) ([morrisjdev](https://github.com/morrisjdev))

0 commit comments

Comments
 (0)