Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wivuu/wivuu.dataseed
Entity Framework data seeding framework
https://github.com/wivuu/wivuu.dataseed
Last synced: 1 day ago
JSON representation
Entity Framework data seeding framework
- Host: GitHub
- URL: https://github.com/wivuu/wivuu.dataseed
- Owner: wivuu
- License: mit
- Created: 2015-06-13T21:37:06.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-10-02T21:23:19.000Z (over 5 years ago)
- Last Synced: 2023-08-05T16:02:18.118Z (over 1 year ago)
- Language: C#
- Size: 2.75 MB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Update 1.0.12
- Updated seed mechanism, DbContext no longer needs to extend SeededDbContext, which has been deprecated.
- 'View' creation system for creating queries of readonly objects(10/12/2016) The below document has been updated to reflect intended usecase.
# Purpose
The purpose of DataSeed is to help you manage the data that gets pre-filled
in your database when using EntityFramework's code-first model. DataSeed helps
you pre-fill your database with lookup tables and testing data.# Usage
## Create a seed
Create a new Seed class (by convention, in a /DataMigrations folder)
to inject data into your database with `update-database`.```C#
public class AddClassesSample : Seed
{
protected Random Random { get; } = new Random(0x01);// Only run this seed once
public override bool ShouldRun(MyDbContext context) =>
context.Classes.Any() == false;
// Apply the seed
public override void Apply(MyDbContext context)
{
// Add classes
context.Classes.Add(new Class
{
Id = Random.NextGuid(),
Name = "Biology 101"
});context.Classes.Add(new Class
{
Id = Random.NextGuid(),
Name = "Physics 201"
});
}
}
```## Invoke the dataseed
Using DataSeed is simple, after installing the package to your code-first
enabled project, open your Configuration.cs file, in the `Seed` method, add
the following call:```C#
protected override void Seed(MyDbContext context)
{
this.Execute(context, new [] {
new AddClassesSample(),
// ... Add more seeds here
});
}
```This is DataSeed's hook into the standard EntityFramework seeding process. Now
DataSeed will automatically be looped in when you invoke `update-database`. The
input Seed classes are run in-order, inside a transaction. If any of the seeds failed,
the transaction is rolled back.## More information
You can find additional information on my blog [here](https://www.eoleary.me/Blog/Seed-Your-Data)## Future
- Further documentation is coming to address usage of 'DbViews'.