Skip to content

timabell/ef-enum-to-lookup

Repository files navigation

Entity Framework 6.1 Enum Lookup Table Generator

About

Creates lookup tables and foreign key constraints based on the enums used in your model.

This makes up for a feature that's missing in Entity Framework 6.1.

Usage

Run EnumToLookup.Apply() from your Seed method in either your database initializer or your EF Migrations.

Use the properties exposed to control behaviour.

It is safe to run repeatedly (Idempotent), and will ensure enum values are kept in line with your current code if run regularly (e.g. in the migration seed method).

For example usage see ExampleUsage/EnumExample.cs, which can be run in the test project project "ExampleUsage" if you want to see it in action.

var enumToLookup = new EnumToLookup();
enumToLookup.NameFieldLength = 42; // optional, example of how to override default values
enumToLookup.Apply(context);

Creating sql scripts

If you can't point this library at your production database and let it make changes then you may need to generate sql in advance. As of v1.7.0 you can do this by running

var migrationSql = enumToLookup.GenerateMigrationSql(context);

instead of Apply() (or as well if you like).

Contributing

Feedback, bug reports, pull requests all welcome, head over to github.

Fund development, PR handling etc: https://www.patreon.com/timabell

Repository

Files stored as LF, converted on checkout to windows, configure locally with

git config core.autocrlf true

I've looked into the .gitattributes approach to this and it doesn't seem to have the desired effect on a windows checkout.

Further reading

About

Generates lookup tables from enum references in Microsoft Entity Framework 6.1

Resources

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages