Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modelBuilder.HasDbFunction on queryable function (of entities) overrides implicit ToTable for that entity #23408

Closed
maumar opened this issue Nov 19, 2020 · 2 comments · Fixed by #25034
Labels
area-model-building breaking-change closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Milestone

Comments

@maumar
Copy link
Contributor

maumar commented Nov 19, 2020

When trying to map tvf using modelBuilder.HasDbFunction, we strip the (by convention) ToTable call.
It makes sense if you use
modelBuilder.Entity<Foo>().ToFunction(...). but is a bit unintuitive when using
modelBuilder.HasDbFunction. especially when the function has some arguments (which would indicate it's just a helper of some sort)

exception:

'The entity type 'Post' is not mapped to a table, therefore the entities cannot be persisted to the database. Call 'ToTable' in 'OnModelCreating' to map it to a table.'

   at Microsoft.EntityFrameworkCore.Update.Internal.CommandBatchPreparer.CreateModificationCommands(IList`1 entries, IUpdateAdapter updateAdapter, Func`1 generateParameterName) in D:\git\efcore\src\EFCore.Relational\Update\Internal\CommandBatchPreparer.cs:line 226
   at Microsoft.EntityFrameworkCore.Update.Internal.CommandBatchPreparer.<BatchCommands>d__10.MoveNext() in D:\git\efcore\src\EFCore.Relational\Update\Internal\CommandBatchPreparer.cs:line 77
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.<GetDataOperations>d__76.MoveNext() in D:\git\efcore\src\EFCore.Relational\Migrations\Internal\MigrationsModelDiffer.cs:line 2174
   at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.<GetDataOperations>d__75.MoveNext() in D:\git\efcore\src\EFCore.Relational\Migrations\Internal\MigrationsModelDiffer.cs:line 2144
   at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Sort(IEnumerable`1 operations, DiffContext diffContext) in D:\git\efcore\src\EFCore.Relational\Migrations\Internal\MigrationsModelDiffer.cs:line 199
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.GetDifferences(IRelationalModel source, IRelationalModel target) in D:\git\efcore\src\EFCore.Relational\Migrations\Internal\MigrationsModelDiffer.cs:line 164
   at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.GetCreateTablesCommands(MigrationsSqlGenerationOptions options) in D:\git\efcore\src\EFCore.Relational\Storage\RelationalDatabaseCreator.cs:line 144
   at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.CreateTables() in D:\git\efcore\src\EFCore.Relational\Storage\RelationalDatabaseCreator.cs:line 123
   at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.EnsureCreated() in D:\git\efcore\src\EFCore.Relational\Storage\RelationalDatabaseCreator.cs:line 236
   at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.EnsureCreated() in D:\git\efcore\src\EFCore\Infrastructure\DatabaseFacade.cs:line 80
@maumar maumar changed the title modelBuilder.HasDbFunction on queryable function (of entities) overrides ToTable modelBuilder.HasDbFunction on queryable function (of entities) overrides ToTable for that entity Nov 19, 2020
@maumar maumar changed the title modelBuilder.HasDbFunction on queryable function (of entities) overrides ToTable for that entity modelBuilder.HasDbFunction on queryable function (of entities) overrides implicit ToTable for that entity Nov 19, 2020
@ajcvickers
Copy link
Member

Note from triage: consider when to map to table automatically, or not, based on how the TVF and return type is used elsewhere.

@ajcvickers ajcvickers added this to the 6.0.0 milestone Nov 20, 2020
AndriySvyryd added a commit that referenced this issue Jun 4, 2021
Preserve null mappings in the model snapshot.
Add non-generic ToSqlQuery overload.
Output Fluent API for ToSqlQuery in the model snapshot.
Fix SetFunctionName setting incorrect annotation.

Fixes #23408
@AndriySvyryd AndriySvyryd removed their assignment Jun 4, 2021
@AndriySvyryd AndriySvyryd added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jun 4, 2021
AndriySvyryd added a commit that referenced this issue Jun 4, 2021
Preserve null mappings in the model snapshot.
Add non-generic ToSqlQuery overload.
Output Fluent API for ToSqlQuery in the model snapshot.
Fix SetFunctionName setting incorrect annotation.

Fixes #23408
AndriySvyryd added a commit that referenced this issue Jun 4, 2021
Preserve null mappings in the model snapshot.
Add non-generic ToSqlQuery overload.
Output Fluent API for ToSqlQuery in the model snapshot.
Fix SetFunctionName setting incorrect annotation.

Fixes #23408
AndriySvyryd added a commit that referenced this issue Jun 4, 2021
Preserve null mappings in the model snapshot.
Add non-generic ToSqlQuery overload.
Output Fluent API for ToSqlQuery in the model snapshot.
Fix SetFunctionName setting incorrect annotation.

Fixes #23408
@ghost ghost closed this as completed in #25034 Jun 8, 2021
ghost pushed a commit that referenced this issue Jun 8, 2021
Preserve null mappings in the model snapshot.
Add non-generic ToSqlQuery overload.
Output Fluent API for ToSqlQuery in the model snapshot.
Fix SetFunctionName setting incorrect annotation.

Fixes #23408
@AndriySvyryd AndriySvyryd modified the milestones: 6.0.0, 6.0.0-preview6 Jul 2, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0-preview6, 6.0.0 Nov 8, 2021
@n0099
Copy link

n0099 commented Feb 7, 2022

The caution addressed in ef core document is still linking to this issue, should it be update with mentions to changes in ef core 6.0?

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-model-building breaking-change closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants