Recognize filters created by fluent API and reverse engineer to fluent API.
See original GitHub issueI define a unique index for a entity Folder
with a nullable property Folder.FolderId
(link to parent folder)
modelBuilder.Entity<Folder>().HasIndex(f => new { f.Name, f.FolderId }).IsUnique();
The debugger shows a Relational:Filter “[FOLDER_ID] IS NOT NULL” annotation defined on that index. The generated DDL looks fine
CREATE UNIQUE INDEX [IX_FOLDERS_NAME_FOLDER_ID] ON [ICNG].[FOLDERS] ([NAME], [FOLDER_ID]) WHERE [FOLDER_ID] IS NOT NULL;
Now if I reverse engineer this database
var reporter = new TestOperationReporter();
var svcColl = new ServiceCollection()
.AddLogging()
.AddSingleton<IOperationReporter>(reporter)
.AddScaffolding(reporter);
new SqlServerDesignTimeServices().ConfigureDesignTimeServices(svcColl);
IServiceProvider prov = svcColl.BuildServiceProvider();
var scaffoldingModelFactory = prov.GetService<IScaffoldingModelFactory>();
var scaffoldedModel = scaffoldingModelFactory.Create(
ConnectionString,
Enumerable.Empty<string>(),
Enumerable.Empty<string>(),
true);
then the Relational:Filter becomes “([FOLDER_ID] IS NOT NULL)” (note the two round brackets). Diffing the original and the scaffolded models yields unnecessary DROP/CREATE INDEX operations, which at first glance doesn’t look correct. Wouldn’t it make sense to reduce the Relational:Filter to a canonical form during scaffolding?
Further technical details
EF Core version: 2.0.0 Database Provider: Microsoft.EntityFrameworkCore.SqlServer Operating system: Windows 10 Pro IDE: Visual Studio 2017
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (11 by maintainers)
Top Results From Across the Web
Reverse Engineering Ef Code First with Fluent Mappings
The Visual Studio wizard which reverse engineers a domain from a database uses a combination of Data Annotations and fluent code in the ......
Read more >The Fluent API HasQueryFilter Method
The Entity Framework Core Fluent API HasQueryFilter method is used to apply a global query filter to a specific entity, so that the...
Read more >In defense of fluent collections API for Python
Introducing a new library with fluent API for collections in Python, ... of functions like map() or filter() common in functional languages.
Read more >Scaffolding (Reverse Engineering) - EF Core
Reverse engineering a model from an existing database using Entity Framework Core. ... For example, using the Fluent API will scaffold this:.
Read more >70-487 Flashcards
Study with Quizlet and memorize flashcards containing terms like What are the major data providers that come with ADO.NET, What data provider is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Unfortunately, reducing expressions returned by the database requires parsing Transact-SQL. We tried this in the past, but it was very error-prone, so we decided to avoid doing it for now.
From what I remember, the parenthesis were actually required in certain cases, so we couldn’t just blindly strip them from every expression.
Today, the provider doesn’t play a role in deciding whether “core” configuration would be applied by convention. We need to add additional provider APIs to enable this.