Support for Fields using Lambda

Improve EF Core performance with EF Extensionsarrow-up-right

arrow-up-right

Support for Fields using Lambda

EF Core 5 allows you to use the lambda methods in the ModelBuilder for fields as well as properties. Let's suppose you don't want to use properties for some reason and decide to use public fields.

public class Book
{
    public int Id;
    public string Title;
    public string Category;
    public int AuthorId;
    public Author Author;
}

public class Author
{
    public int Id;
    public string Name;
    public ICollection<Book> Books;
}

In EF Core 5, you can map these fields using the lambda builders as shown below.

It will create the following tables on the SQL Server.

Before EF Core 5, if you try to map these fields using the model builder, It will throw the following exception.

Last updated