https://github.com/karenpayneoregon/entityframeworkenum
Entity Framework 6 Enum support
https://github.com/karenpayneoregon/entityframeworkenum
database entity-framework
Last synced: about 2 months ago
JSON representation
Entity Framework 6 Enum support
- Host: GitHub
- URL: https://github.com/karenpayneoregon/entityframeworkenum
- Owner: karenpayneoregon
- Created: 2019-08-02T14:25:05.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-06-04T11:50:45.000Z (about 4 years ago)
- Last Synced: 2025-10-12T19:04:26.854Z (9 months ago)
- Topics: database, entity-framework
- Language: C#
- Homepage:
- Size: 104 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# TechNet article
Entity Framework database/Code First Enum support
https://social.technet.microsoft.com/wiki/contents/articles/53169.entity-framework-databasecode-first-enum-support.aspx
**See also**
[Windows forms Entity Framework Code first from database](https://social.technet.microsoft.com/wiki/contents/articles/53154.windows-forms-entity-framework-code-first-from-database.aspx)
# EF Core Value Conversions
See the following [repository](https://github.com/karenpayneoregon/ef-core-transforming) for working with `enum` and more.
Example, `BookCatgory` is an `enum`
```csharp
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS");
modelBuilder
.Entity()
.Property(e => e.BookCategory)
.HasConversion();
modelBuilder
.Entity().HasData(
Enum.GetValues(typeof(BookCategory))
.Cast()
.Select(e => new BookVariant()
{
BookCategoryId = e,
Name = e.ToString()
})
);
}
```
**Sample query**
```csharp
var list = bookList.Where(books => books.BookCategory == BookCategory.Adventure).ToList();
```