{"id":30623,"date":"2020-11-10T08:50:27","date_gmt":"2020-11-10T15:50:27","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/dotnet\/?p=30623"},"modified":"2020-11-16T12:16:31","modified_gmt":"2020-11-16T19:16:31","slug":"announcing-the-release-of-ef-core-5-0","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-the-release-of-ef-core-5-0\/","title":{"rendered":"Announcing the Release of EF Core 5.0"},"content":{"rendered":"<p>Today, the Entity Framework team is delighted to announce the release of <a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore\/5.0.0\">EF Core 5.0<\/a>. This is a general availability\/release to manufacturing (GA\/RTM) release that addresses final bugs identified in the previous release candidates and is ready for production. EF Core 5.0 is released simultaneously with <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-net-5-0\/\">.NET 5.0<\/a>.<\/p>\n<h2>What&#8217;s new in EF Core 5.0<\/h2>\n<p>The early releases of EF Core focused on building a flexible and extensible architecture. In EF Core 3.1, the team buttoned down this architecture with some breaking changes and an overhauled query pipeline. The foundation from 3.1 enabled the team and community to deliver an astonishing set of new features for EF Core 5.0. Some of the highlights from the <a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-5.0\/whatsnew\">81 significant enhancements<\/a> include:<\/p>\n<ul>\n<li><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-5.0\/whatsnew#many-to-many\">Many-to-many relationship mapping<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-5.0\/whatsnew#table-per-type-tpt-mapping\">Table-per-type inheritance mapping<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-5.0\/whatsnew#indexattribute\">IndexAttribute to map indexes without the fluent API<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-5.0\/whatsnew#database-collations\">Database collations<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-5.0\/whatsnew#filtered-include\">Filtered Include<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/miscellaneous\/events\/simple-logging\">Simple logging<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-5.0\/whatsnew#exclude-tables-from-migrations\">Exclude tables from migrations<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-5.0\/whatsnew#split-queries-for-related-collections\">Split queries for related collections<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-5.0\/whatsnew#event-counters\">Event counters<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-5.0\/whatsnew#savechanges-interception-and-events\">SaveChanges interception and events<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-5.0\/whatsnew#required-11-dependents\">Required 1:1 dependents<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-5.0\/whatsnew#migrations-scripts-with-transactions\">Migrations scripts with transactions<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-5.0\/whatsnew#migrations-rebuild-sqlite-tables\">Rebuild SQLite tables as needed in migrations<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-5.0\/whatsnew#table-valued-functions\">Mapping for table-valued functions<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-5.0\/whatsnew#dbcontextfactory\">DbContextFactory support for dependency injection<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-5.0\/whatsnew#reset-dbcontext-state\">ChangeTracker.Clear to stop tracking all entities<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-5.0\/whatsnew#cosmos-configuration\">Improved Cosmos configuration<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-5.0\/whatsnew#change-tracking-proxies\">Change-tracking proxies<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-5.0\/whatsnew#property-bags\">Property bags<\/a><\/li>\n<\/ul>\n<p>These new features are part of a larger pool of changes:<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/dotnet\/efcore\/issues?q=is%3Aissue+milestone%3A5.0.0+is%3Aclosed+label%3Atype-enhancement\">Almost 240 enhancements<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/dotnet\/efcore\/issues?q=is%3Aissue+milestone%3A5.0.0+is%3Aclosed+label%3Atype-bug\">Over 380 bug fixes<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/dotnet\/efcore\/issues?q=is%3Aissue+milestone%3A5.0.0+is%3Aclosed+-label%3Atype-bug+-label%3Atype-enhancement+\">Over 80 cleanup and API documentation updates<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/dotnet\/EntityFramework.Docs\/issues?q=is%3Aissue+milestone%3A5.0.0+is%3Aclosed\">Over 120 updates to documentation pages<\/a><\/li>\n<\/ul>\n<h2>What the community is saying<\/h2>\n<p>With so much goodness in EF Core 5.0 it was hard to decide what to cover in the announcement blog post! The team reached out to four pillars of the EF Core community and asked them to weigh in with their favorite features in EF Core 5.0. Here&#8217;s what they had to say.<\/p>\n<blockquote>\n<p><strong>\ud83d\udcc5 Mark your calendar<\/strong> On Wednesday, November 18th at 10am Pacific Time, the EF Core team will host a special edition of the EF Core Community Standup. Our special guests from the EF Core community will join a live panel discussion about the latest features. Join us and have your EF Core 5.0 questions answered! Details will be posted to the <a href=\"https:\/\/live.dot.net\/\">.NET Live<\/a> page.<\/p>\n<\/blockquote>\n<h3>Julie Lerman: Simple logging<\/h3>\n<p><a href=\"https:\/\/twitter.com\/julielerman\">Julie Lerman<\/a> is a software coach, <a href=\"https:\/\/www.pluralsight.com\/authors\/julie-lerman\">Pluralsight author<\/a> and longtime user of Entity Framework.<\/p>\n<p>EF Core has always integrated with the <a href=\"https:\/\/docs.microsoft.com\/aspnet\/core\/fundamentals\/logging\/?view=aspnetcore-3.1\">Microsoft.Extensions.Logging<\/a> infrastructure. This form of logging is powerful and extensible, but requires external dependencies and configuration.  EF Core 5.0 introduces the <a href=\"https:\/\/docs.microsoft.com\/ef\/core\/miscellaneous\/events\/simple-logging\">LogTo method<\/a> as a simple way to obtain logs while developing and debugging without installing additional dependencies.<\/p>\n<p><code>LogTo<\/code> is called when <a href=\"https:\/\/docs.microsoft.com\/ef\/core\/miscellaneous\/configuring-dbcontext\">configuring a DbContext instance<\/a>. This configuration is commonly done in an override of <code>DbContext.OnConfiguring<\/code>. For example:<\/p>\n<pre><code class=\"CSharp\">protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)\r\n    =&gt; optionsBuilder\r\n        .EnableSensitiveDataLogging()\r\n        .EnableDetailedErrors()\r\n        .LogTo(Console.WriteLine);\r\n<\/code><\/pre>\n<p>Alternately, LogTo can be called as part of <code>AddDbContext<\/code> or when creating a <code>DbContextOptions<\/code> instance to pass to the <code>DbContext<\/code> constructor. For example:<\/p>\n<pre><code class=\"CSharp\">serviceCollection.AddDbContext&lt;SomeDbContext&gt;(\r\n    b =&gt; b.UseSqlServer(Your.ConnectionString)\r\n        .EnableSensitiveDataLogging()\r\n        .EnableDetailedErrors()\r\n        .LogTo(Console.WriteLine));\r\n<\/code><\/pre>\n<p>Both examples set up logging to the console and also turn on sensitive data logging and detailed errors for the best debugging experience. This results in log output to console; for example:<\/p>\n<pre><code class=\"text\">warn: 11\/4\/2020 12:59:56.097 CoreEventId.SensitiveDataLoggingEnabledWarning[10400] (Microsoft.EntityFrameworkCore.Infrastructure)\r\n      Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data; this mode should only be enabled during development.\r\ninfo: 11\/4\/2020 12:59:56.190 CoreEventId.ContextInitialized[10403] (Microsoft.EntityFrameworkCore.Infrastructure)\r\n      Entity Framework Core 5.0.0-rc.2.20475.6 initialized 'SomeDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: SensitiveDataLoggingEnabled\r\ndbug: 11\/4\/2020 12:59:56.221 RelationalEventId.ConnectionOpening[20000] (Microsoft.EntityFrameworkCore.Database.Connection)\r\n      Opening connection to database 'Test' on server '(local)'.\r\n<\/code><\/pre>\n<p>See the <a href=\"https:\/\/docs.microsoft.com\/ef\/core\/miscellaneous\/events\/simple-logging\">simple logging documentation<\/a> for more information on:<\/p>\n<ul>\n<li>Logging to the debug window or a file<\/li>\n<li>Log filtering<\/li>\n<li>Message contents and formatting<\/li>\n<\/ul>\n<blockquote>\n<p>&#8220;It\u2019s a beautiful blend of the simplicity of logging in EF6 and the intelligence of .NET Core logging functionality.&#8221; &mdash; Julie<\/p>\n<\/blockquote>\n<h3>Diego Vega: Many-to-many (M2M) relationships<\/h3>\n<p><a href=\"https:\/\/twitter.com\/divega\">Diego Vega<\/a> is a principal software engineer at Microsoft on the Azure networking team. He formerly served as program manager for the EF Core team.<\/p>\n<p>EF Core 5.0 supports many-to-many relationships without explicitly mapping the join table.<\/p>\n<p>For example, consider these entity types:<\/p>\n<pre><code class=\"CSharp\">public class Post\r\n{\r\n    public int Id { get; set; }\r\n    public string Name { get; set; }\r\n    public ICollection&lt;Tag&gt; Tags { get; set; }\r\n}\r\n\r\npublic class Tag\r\n{\r\n    public int Id { get; set; }\r\n    public string Text { get; set; }\r\n    public ICollection&lt;Post&gt; Posts { get; set; }\r\n}\r\n<\/code><\/pre>\n<p>Notice that <code>Post<\/code> contains a collection of <code>Tags<\/code>, and <code>Tag<\/code> contains a collection of <code>Posts<\/code>. EF Core 5.0 recognizes this as a many-to-many relationship by convention. This means no code is required in <code>OnModelCreating<\/code>:<\/p>\n<pre><code class=\"CSharp\">public class BlogContext : DbContext\r\n{\r\n    public DbSet&lt;Post&gt; Posts { get; set; }\r\n    public DbSet&lt;Blog&gt; Blogs { get; set; }\r\n}\r\n<\/code><\/pre>\n<p>When Migrations (or <code>EnsureCreated<\/code>) are used to create the database, EF Core will automatically create the join table. For example, on SQL Server for this model, EF Core generates:<\/p>\n<pre><code class=\"sql\">CREATE TABLE [Posts] (\r\n    [Id] int NOT NULL IDENTITY,\r\n    [Name] nvarchar(max) NULL,\r\n    CONSTRAINT [PK_Posts] PRIMARY KEY ([Id]));\r\n\r\nCREATE TABLE [Tags] (\r\n    [Id] int NOT NULL IDENTITY,\r\n    [Text] nvarchar(max) NULL,\r\n    CONSTRAINT [PK_Tags] PRIMARY KEY ([Id]));\r\n\r\nCREATE TABLE [PostTag] (\r\n    [PostsId] int NOT NULL,\r\n    [TagsId] int NOT NULL,\r\n    CONSTRAINT [PK_PostTag] PRIMARY KEY ([PostsId], [TagsId]),\r\n    CONSTRAINT [FK_PostTag_Posts_PostsId] FOREIGN KEY ([PostsId]) REFERENCES [Posts] ([Id]) ON DELETE CASCADE,\r\n    CONSTRAINT [FK_PostTag_Tags_TagsId] FOREIGN KEY ([TagsId]) REFERENCES [Tags] ([Id]) ON DELETE CASCADE);\r\n\r\nCREATE INDEX [IX_PostTag_TagsId] ON [PostTag] ([TagsId]);\r\n<\/code><\/pre>\n<p>Creating and associating <code>Blog<\/code> and <code>Post<\/code> entities results in join table updates happening automatically. For example:<\/p>\n<pre><code class=\"CSharp\">var beginnerTag = new Tag {Text = \"Beginner\"};\r\nvar advancedTag = new Tag {Text = \"Advanced\"};\r\nvar efCoreTag = new Tag {Text = \"EF Core\"};\r\n\r\ncontext.AddRange(\r\n    new Post {Name = \"EF Core 101\", Tags = new List&lt;Tag&gt; {beginnerTag, efCoreTag}},\r\n    new Post {Name = \"Writing an EF database provider\", Tags = new List&lt;Tag&gt; {advancedTag, efCoreTag}},\r\n    new Post {Name = \"Savepoints in EF Core\", Tags = new List&lt;Tag&gt; {beginnerTag, efCoreTag}});\r\n\r\ncontext.SaveChanges();\r\n<\/code><\/pre>\n<p>After inserting the Posts and Tags, EF will then automatically create rows in the join table. For example, on SQL Server:<\/p>\n<pre><code class=\"text\">Executed DbCommand (8ms) [Parameters=[@p6='1', @p7='1', @p8='1', @p9='2', @p10='2', @p11='2', @p12='2', @p13='3', @p14='3', @p15='1', @p16='3', @p17='2'], CommandType='Text', CommandTimeout='30']\r\n      SET NOCOUNT ON;\r\n      INSERT INTO [PostTag] ([PostsId], [TagsId])\r\n      VALUES (@p6, @p7),\r\n      (@p8, @p9),\r\n      (@p10, @p11),\r\n      (@p12, @p13),\r\n      (@p14, @p15),\r\n      (@p16, @p17);\r\n<\/code><\/pre>\n<p>For queries, <code>Include<\/code> and other query operations work just like for any other relationship. For example:<\/p>\n<pre><code class=\"CSharp\">foreach (var post in context.Posts.Include(e =&gt; e.Tags))\r\n{\r\n    Console.Write($\"Post \"{post.Name}\" has tags\");\r\n\r\n    foreach (var tag in post.Tags)\r\n    {\r\n        Console.Write($\" '{tag.Text}'\");\r\n    }\r\n}\r\n<\/code><\/pre>\n<p>The SQL generated uses the join table automatically to bring back all related Tags:<\/p>\n<pre><code class=\"sql\">SELECT [p].[Id], [p].[Name], [t0].[PostsId], [t0].[TagsId], [t0].[Id], [t0].[Text]\r\nFROM [Posts] AS [p]\r\nLEFT JOIN (\r\n    SELECT [p0].[PostsId], [p0].[TagsId], [t].[Id], [t].[Text]\r\n    FROM [PostTag] AS [p0]\r\n    INNER JOIN [Tags] AS [t] ON [p0].[TagsId] = [t].[Id]\r\n) AS [t0] ON [p].[Id] = [t0].[PostsId]\r\nORDER BY [p].[Id], [t0].[PostsId], [t0].[TagsId], [t0].[Id]\r\n<\/code><\/pre>\n<p>Unlike EF6, EF Core allows full customization of the join table. For example, the code below configures a many-to-many relationship that also has navigations to the join entity, and in which the join entity contains a payload property:<\/p>\n<pre><code class=\"CSharp\">protected override void OnModelCreating(ModelBuilder modelBuilder)\r\n{\r\n    modelBuilder\r\n        .Entity&lt;Post&gt;()\r\n        .HasMany(p =&gt; p.Tags)\r\n        .WithMany(p =&gt; p.Posts)\r\n        .UsingEntity&lt;PostTag&gt;(\r\n            j =&gt; j.HasOne(pt =&gt; pt.Tag).WithMany().HasForeignKey(pt =&gt; pt.TagId),\r\n            j =&gt; j.HasOne(pt =&gt; pt.Post).WithMany().HasForeignKey(pt =&gt; pt.PostId),\r\n            j =&gt;\r\n            {\r\n                j.Property(pt =&gt; pt.PublicationDate).HasDefaultValueSql(\"CURRENT_TIMESTAMP\");\r\n                j.HasKey(t =&gt; new { t.PostId, t.TagId });\r\n            });\r\n}\r\n<\/code><\/pre>\n<p>See <a href=\"https:\/\/docs.microsoft.com\/ef\/core\/modeling\/relationships?tabs=fluent-api%2Cfluent-api-simple-key%2Csimple-key#many-to-many\">configuring many-to-many relationships<\/a> to learn more about more complex mappings like this.<\/p>\n<blockquote>\n<p>&#8220;I choose many-to-many because it comes with a payload of additional features.&#8221; &mdash; Diego<\/p>\n<\/blockquote>\n<h3>Jon P Smith: ChangeTracker.Clear()<\/h3>\n<p><a href=\"https:\/\/twitter.com\/thereformedprog\">Jon P Smith<\/a> is a .NET Core backend developer, architect, and the author of <a href=\"https:\/\/www.manning.com\/books\/entity-framework-core-in-action-second-edition\">Entity Framework Core in Action<\/a>.<\/p>\n<p>As with all EF Core releases, the team implements big features, but also many smaller usability improvements. The new <code>DbContext.ChangeTracker.Clear()<\/code> method is one of these improvements. It clears the EF change tracker so that all currently tracked entities are detached. For example:<\/p>\n<pre><code class=\"CSharp\">using (var context = new BlogContext())\r\n{\r\n    \/\/ A normal tracking query brings entities into the context\r\n    var postsAndTags = context.Posts.Include(e =&gt; e.Tags).ToList();\r\n    Debug.Assert(context.ChangeTracker.Entries().Count() == 12);\r\n\r\n    \/\/ These can then used for one or more updates\r\n    postsAndTags.First().Name = \"EF Core 102\";\r\n    context.SaveChanges();\r\n    Debug.Assert(context.ChangeTracker.Entries().Count() == 12);\r\n\r\n    \/\/ All tracked entities can then be detached\r\n    context.ChangeTracker.Clear();\r\n    Debug.Assert(context.ChangeTracker.Entries().Count() == 0);\r\n}\r\n<\/code><\/pre>\n<p>Note that calling <code>ChangeTracker.Clear()<\/code> in this example should usually not be needed when using the best practice of creating a new, short-lived context instance for each unit-of-work. However, sometimes application architecture can make it hard to use a new <code>DbContext<\/code> for each unit-of-work. For these case, using <code>ChangeTracker.Clear()<\/code> is more performant and robust than mass-detaching all entities.<\/p>\n<blockquote>\n<p>&#8220;My favorite EF Core 5 feature is <code>ChangeTracker.Clear()<\/code>. I use this in my unit tests to clear out any database setup entity classes so that when I run my tests I know it&#8217;s read new data from the database.&#8221; &mdash; Jon<\/p>\n<\/blockquote>\n<h3>Erik Ejlskov Jensen: Improved database-first scaffolding<\/h3>\n<p><a href=\"https:\/\/twitter.com\/ErikEJ\">Erik Ejlskov Jensen<\/a> is a Tech Lead at <em>VENZO_nxt<\/em> and maintains the popular <a href=\"https:\/\/github.com\/ErikEJ\/EFCorePowerTools\">EF Core Power Tools<\/a> that provides reverse engineering, migrations, and model visualization for EF Core.<\/p>\n<p>EF Core 5.0 includes many improvements for scaffolding (a.k.a. reverse-engineering) a <code>DbContext<\/code> for a database-first experience. These are features that can be both used from the command-line tools that ship with EF, or with community projects like Erik&#8217;s visual EF Core Power Tools. The following sections show some examples.<\/p>\n<h4>Scaffold to custom namespaces<\/h4>\n<p>EFCore 5.0 supports <a href=\"https:\/\/docs.microsoft.com\/ef\/core\/managing-schemas\/scaffolding?tabs=dotnet-core-cli#directories-and-namespaces\">overriding the namespace<\/a> for all scaffolded classes. In addition, if desired, a different namespace can be configured for the <code>DbContext<\/code> class. For example:<\/p>\n<pre><code class=\"bash\">dotnet ef dbcontext scaffold ... --namespace Your.Namespace --context-namespace Your.DbContext.Namespace\r\n<\/code><\/pre>\n<blockquote>\n<p><strong>\ud83d\udca1 TIP<\/strong> We are showing the .NET command line tool here, but the same options are available in the Package Manager Console PowerShell commands.<\/p>\n<\/blockquote>\n<h4>Stop scaffolding the connection string<\/h4>\n<p>By default, EF Core includes the connection string for the scaffolded database in a call to <code>OnConfiguring<\/code> on the generated <code>DbContext<\/code>. However, this can be frustrating for applications that already configure the <code>DbContext<\/code> in some other way; for example, inside <code>AddDbContext<\/code> in an ASP.NET Core application. EF Core 5.0 supports scaffolding a <code>DbContext<\/code> without including a call to <code>OnConfiguring<\/code>. For example:<\/p>\n<pre><code class=\"bash\">dotnet ef dbcontext scaffold ... --no-onconfiguring\r\n<\/code><\/pre>\n<h4>Pluralization<\/h4>\n<p>EF Core now integrates with <a href=\"https:\/\/github.com\/Humanizr\/Humanizer\">Humanizer<\/a> to provide pluralization by default when scaffolding from a database. Putting all this together, here&#8217;s an example command using custom namespaces, no <code>OnConfiguring<\/code>, and the default pluralization support:<\/p>\n<pre><code class=\"bash\">dotnet ef dbcontext scaffold 'Server=(local);Database=Blogs;User Id=arthur;Password=Unicorns4All' \r\n Microsoft.EntityFrameworkCore.SqlServer --namespace Blogs.Entities \r\n --context-namespace Blogs.Context --no-onconfiguring --data-annotations\r\n<\/code><\/pre>\n<p>This results in the following classes being generated:<\/p>\n<pre><code class=\"CSharp\">#nullable disable\r\n\r\nnamespace Blogs.Context\r\n{\r\n    public partial class BlogsContext : DbContext\r\n    {\r\n        public BlogsContext()\r\n        {\r\n        }\r\n\r\n        public BlogsContext(DbContextOptions&lt;BlogsContext&gt; options)\r\n            : base(options)\r\n        {\r\n        }\r\n\r\n        public virtual DbSet&lt;Blog&gt; Blogs { get; set; }\r\n        public virtual DbSet&lt;Post&gt; Posts { get; set; }\r\n\r\n        protected override void OnModelCreating(ModelBuilder modelBuilder)\r\n        {\r\n            OnModelCreatingPartial(modelBuilder);\r\n        }\r\n\r\n        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);\r\n    }\r\n}\r\n<\/code><\/pre>\n<pre><code class=\"CSharp\">#nullable disable\r\n\r\nnamespace Blogs.Entities\r\n{\r\n    [Index(nameof(BlogId), Name = \"IX_Posts_BlogId\")]\r\n    public partial class Post\r\n    {\r\n        [Key]\r\n        public int Id { get; set; }\r\n        public string Title { get; set; }\r\n        public string Content { get; set; }\r\n        public int? BlogId { get; set; }\r\n\r\n        [ForeignKey(nameof(BlogId))]\r\n        [InverseProperty(\"Posts\")]\r\n        public virtual Blog Blog { get; set; }\r\n    }\r\n}\r\n<\/code><\/pre>\n<pre><code class=\"CSharp\">#nullable disable\r\n\r\nnamespace Blogs.Entities\r\n{\r\n    public partial class Blog\r\n    {\r\n        public Blog()\r\n        {\r\n            Posts = new HashSet&lt;Post&gt;();\r\n        }\r\n\r\n        [Key]\r\n        public int Id { get; set; }\r\n        public string Name { get; set; }\r\n\r\n        [InverseProperty(nameof(Post.Blog))]\r\n        public virtual ICollection&lt;Post&gt; Posts { get; set; }\r\n    }\r\n}\r\n<\/code><\/pre>\n<p>Notice that:<\/p>\n<ul>\n<li><code>DbSet<\/code> property names are pluralized<\/li>\n<li>The entity types are in one namespace and the <code>DbContext<\/code> is in another<\/li>\n<li>There is no <code>OnConfiguring<\/code> method containing my connection string<\/li>\n<li>The new <code>IndexAttribute<\/code> is used instead of generating code in <code>OnModelCreating<\/code><\/li>\n<li><code>#nullable disable<\/code> is generated since EF Core does not currently reverse-engineer to nullable reference types<\/li>\n<\/ul>\n<p>See the <a href=\"https:\/\/docs.microsoft.com\/ef\/core\/managing-schemas\/scaffolding?tabs=dotnet-core-cli\">documentation for reverse-engineering<\/a> for more information.<\/p>\n<blockquote>\n<p>&#8220;The many small feature additions to database first scaffolding are amongst my favorite features in EF Core 5: Namespace, no connection string on generated code, pluralization &#8211; all features that help improve EF Core Power Tools as well&#8221; &mdash; Erik<\/p>\n<\/blockquote>\n<h2>Learn more<\/h2>\n<p>There are many good sources of information about EF Core.<\/p>\n<ul>\n<li>The <a href=\"https:\/\/docs.microsoft.com\/ef\/\">official documentation<\/a> contains everything from getting-started guides to advanced feature documentation<\/li>\n<li>Keep up with the latest changes in the <a href=\"https:\/\/github.com\/dotnet\/efcore\/issues\/19549\">EF Core weekly updates<\/a><\/li>\n<li>The team live streams a <a href=\"https:\/\/www.youtube.com\/playlist?list=PL1rZQsJPBU2Ry_KbYPklhVu0JhP0kOFbj\">community standup<\/a> every few weeks, including guests, news, and demos<\/li>\n<li>Ask questions on <a href=\"https:\/\/github.com\/dotnet\/efcore\/issues\">GitHub<\/a> or <a href=\"https:\/\/stackoverflow.com\/questions\/tagged\/entity-framework-core\">Stack Overflow<\/a><\/li>\n<li>There are many great books, online courses, and blog posts about EF Core out there from the likes of Julie, Jon, Erik, and many others. (If you find something really good, then let us know and we&#8217;ll feature it on the community standup.)<\/li>\n<\/ul>\n<p>Or contact the team for any reason on <a href=\"https:\/\/github.com\/dotnet\/efcore\">GitHub<\/a> or <a href=\"https:\/\/twitter.com\/i\/lists\/1253069921669410818\">Twitter<\/a>.<\/p>\n<h2>How to get EF Core 5.0<\/h2>\n<p>EF Core 5.0 requires a <a href=\"https:\/\/github.com\/dotnet\/standard\/blob\/master\/docs\/versions\/netstandard2.1.md\">.NET Standard 2.1<\/a> platform. This means EF Core 5.0 will run on .NET Core 3.1 or .NET 5, as well as other <a href=\"https:\/\/docs.microsoft.com\/dotnet\/standard\/net-standard#net-implementation-support\">platforms that support .NET Standard 2.1<\/a>. EF Core 5.0 does not run on .NET Framework.<\/p>\n<p>EF Core 5.0 is distributed exclusively as a set of NuGet packages. For example, to add the SQL Server provider to your project, you can use the following command using the dotnet tool:<\/p>\n<pre><code class=\"bash\">dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 5.0.0\r\n<\/code><\/pre>\n<p>This following table links to the release versions of the EF Core packages and describes what they are used for.<\/p>\n<table>\n<thead>\n<tr>\n<th align=\"left\"><strong>Package<\/strong><\/th>\n<th align=\"left\"><strong>Purpose<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"left\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore\/5.0.0\">Microsoft.EntityFrameworkCore<\/a><\/td>\n<td align=\"left\">The main EF Core package that is independent of specific database providers<\/td>\n<\/tr>\n<tr>\n<td align=\"left\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.SqlServer\/5.0.0\">Microsoft.EntityFrameworkCore.SqlServer<\/a><\/td>\n<td align=\"left\">Database provider for Microsoft SQL Server and SQL Azure<\/td>\n<\/tr>\n<tr>\n<td align=\"left\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite\/5.0.0\">Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite<\/a><\/td>\n<td align=\"left\">SQL Server support for spatial types<\/td>\n<\/tr>\n<tr>\n<td align=\"left\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Sqlite\/5.0.0\">Microsoft.EntityFrameworkCore.Sqlite<\/a><\/td>\n<td align=\"left\">Database provider for SQLite that includes the native binary for the database engine<\/td>\n<\/tr>\n<tr>\n<td align=\"left\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite\/5.0.0\">Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite<\/a><\/td>\n<td align=\"left\">SQLite support for spatial types<\/td>\n<\/tr>\n<tr>\n<td align=\"left\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Cosmos\/5.0.0\">Microsoft.EntityFrameworkCore.Cosmos<\/a><\/td>\n<td align=\"left\">Database provider for Azure Cosmos DB<\/td>\n<\/tr>\n<tr>\n<td align=\"left\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.InMemory\/5.0.0\">Microsoft.EntityFrameworkCore.InMemory<\/a><\/td>\n<td align=\"left\">The in-memory database provider<\/td>\n<\/tr>\n<tr>\n<td align=\"left\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Tools\/5.0.0\">Microsoft.EntityFrameworkCore.Tools<\/a><\/td>\n<td align=\"left\">EF Core PowerShell commands for the Visual Studio Package Manager Console; use this to integrate tools like <a href=\"https:\/\/docs.microsoft.com\/ef\/core\/managing-schemas\/scaffolding\">scaffolding<\/a> and <a href=\"https:\/\/docs.microsoft.com\/ef\/core\/managing-schemas\/migrations\/\">migrations<\/a> with Visual Studio<\/td>\n<\/tr>\n<tr>\n<td align=\"left\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Design\/5.0.0\">Microsoft.EntityFrameworkCore.Design<\/a><\/td>\n<td align=\"left\">Shared design-time components for EF Core tools<\/td>\n<\/tr>\n<tr>\n<td align=\"left\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Proxies\/5.0.0\">Microsoft.EntityFrameworkCore.Proxies<\/a><\/td>\n<td align=\"left\">Lazy-loading and change-tracking proxies<\/td>\n<\/tr>\n<tr>\n<td align=\"left\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Abstractions\/5.0.0\">Microsoft.EntityFrameworkCore.Abstractions<\/a><\/td>\n<td align=\"left\">Decoupled EF Core abstractions; use this for features like extended data annotations defined by EF Core<\/td>\n<\/tr>\n<tr>\n<td align=\"left\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Relational\/5.0.0\">Microsoft.EntityFrameworkCore.Relational<\/a><\/td>\n<td align=\"left\">Shared EF Core components for relational database providers<\/td>\n<\/tr>\n<tr>\n<td align=\"left\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Analyzers\/5.0.0\">Microsoft.EntityFrameworkCore.Analyzers<\/a><\/td>\n<td align=\"left\">C# analyzers for EF Core<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Installing the EF Core Command Line Interface (CLI)<\/h2>\n<p>As with EF Core 3.0 and 3.1, the EF Core 5.0 CLI is no longer included in the .NET Core SDK. Before you can execute EF Core migration or scaffolding commands, you&#8217;ll have to install this package as either a global or local tool.<\/p>\n<p>To install the 5.0 tool globally the first time, use:<\/p>\n<pre><code class=\"bash\">dotnet tool install --global dotnet-ef --version 5.0.0\r\n<\/code><\/pre>\n<p>If you already have the tool installed, update it with:<\/p>\n<pre><code class=\"bash\">dotnet tool update --global dotnet-ef --version 5.0.0\r\n<\/code><\/pre>\n<p>It\u2019s possible to use this new version of the EF Core CLI with projects that use older versions of the EF Core runtime.<\/p>\n<h2>Special thanks<\/h2>\n<p>Development on EF Core is lead by a small team at Microsoft. However, many members of the community contributed to EF Core 5.0, either with code, documentation, or both. Many thanks from the team to everybody who helped us deliver this release!<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-entity-framework-core-efcore-5-0-rc1\/#thank-you-to-our-contributors-\">View the full list of contributors<\/a><\/p>\n<p>In addition, a special thank you this release to Diego Vega, our former program manager, who has been fundamental to the design and direction of EF Core over the years. In particular, Diego was a major contributor to the overall design for extensible many-to-many relationships.<\/p>\n<h2>Conclusion<\/h2>\n<p>Finally, a big thank you to the entire EF community for feedback, support, and bug reports, not to mention the occasional rant! Start <a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore\/5.0.0\">using EF Core 5.0<\/a> now and continue filing bugs, voting on issues, and letting us know what you need from EF Core.<\/p>\n<p>Thank you,<\/p>\n<p>The EF Core Team<\/p>\n<table>\n<thead>\n<tr>\n<th align=\"center\"><\/th>\n<th align=\"center\"><\/th>\n<th align=\"center\"><\/th>\n<th align=\"center\"><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"center\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/03\/efteam_ajcvickers.jpeg\" alt=\"Arthur Vickers\" \/><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/03\/efteam_AndriySvyryd.jpeg\" alt=\"Andriy Svyryd\" \/><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/03\/efteam_bricelam.jpeg\" alt=\"Brice Lambson\" \/><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/03\/efteam_JeremyLikness.jpeg\" alt=\"Jeremy Likness\" \/><\/td>\n<\/tr>\n<tr>\n<td align=\"center\"><a href=\"https:\/\/github.com\/ajcvickers\">Arthur Vickers<\/a><\/td>\n<td align=\"center\"><a href=\"https:\/\/github.com\/AndriySvyryd\">Andriy Svyryd<\/a><\/td>\n<td align=\"center\"><a href=\"https:\/\/github.com\/bricelam\">Brice Lambson<\/a><\/td>\n<td align=\"center\"><a href=\"https:\/\/github.com\/JeremyLikness\">Jeremy Likness<\/a><\/td>\n<\/tr>\n<tr>\n<td align=\"center\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/03\/efteam_maumar.jpeg\" alt=\"Maurycy Markowski\" \/><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/03\/efteam_roji-1-300x300.png\" alt=\"Shay Rojansky\" \/><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/03\/efteam_smitpatel.png\" alt=\"Smit Patel\" \/><\/td>\n<td align=\"center\"><\/td>\n<\/tr>\n<tr>\n<td align=\"center\"><a href=\"https:\/\/github.com\/maumar\">Maurycy Markowski<\/a><\/td>\n<td align=\"center\"><a href=\"https:\/\/github.com\/roji\">Shay Rojansky<\/a><\/td>\n<td align=\"center\"><a href=\"https:\/\/github.com\/smitpatel\">Smit Patel<\/a><\/td>\n<td align=\"center\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Announcing the release of EF Core 5.0, a full featured cross-platform version of Entity Framework that delivers the most requested features like Many-to-Many and Table-Per-Type.<\/p>\n","protected":false},"author":368,"featured_media":30624,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[685,196,197,859],"tags":[9,30,70,71],"class_list":["post-30623","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet","category-dotnet-core","category-aspnet","category-entity-framework","tag-net-core","tag-announcement","tag-entity-framework","tag-entity-framework-core"],"acf":[],"blog_post_summary":"<p>Announcing the release of EF Core 5.0, a full featured cross-platform version of Entity Framework that delivers the most requested features like Many-to-Many and Table-Per-Type.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/30623","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/368"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=30623"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/30623\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/30624"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=30623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=30623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=30623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}