An open API service indexing awesome lists of open source software.

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

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();
```