question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Recognize filters created by fluent API and reverse engineer to fluent API.

See original GitHub issue

I 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:open
  • Created 6 years ago
  • Comments:15 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
bricelamcommented, Oct 30, 2017

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.

0reactions
bricelamcommented, Mar 16, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found