Entity Framework Core 3.x Mapping procedures without creating tables

c# ef-core-3.0 ef-core-3.1 entity-framework-core

Question

How can i map a stored procedure to a class that i don't want to create a table? Query is deprecated. Or... I could use an existing Entity but how can i add properties that i don't want to be created on database? Just work as placeholders for stored procedure

Right now all i have is this but it will create tables for it

  public DbSet<ProcedureLocalization> ProcesureGetLocalizations { get; set; }
  public DbSet<ProcedureRandomLocalization> ProcedureGetRandomLocalizations { get; set; }
1
0
3/5/2020 7:54:14 PM

Accepted Answer

This is a known defect in EF Core 3, reported here 3.0 Upgrade - Entity with HasNoKey() (formerly a query type) tries to create tables when adding migration #18116.

Closed as "duplicate" of To vs From methods: Proposal to rationalize ToTable, ToQuery, ToView, FromSql, and other related methods #17270 and Ability to exclude/skip/ignore parts of the model from migrations so that a table is not created (for overlapping bounded contexts) #2725, both scheduled for 5.0 release, which means it would eventually be addressed in that release.

The current workaround is mentioned in the comments by one of the EF Core team members:

For now, you can just use something like .ToView("You forgot to use FromSql with ModQueueEntry")

or more generally, using .ToView(null), e.g.

modelBuilder.Entity<CustomQuery>().HasNoKey().ToView(null);
2
2/5/2020 3:29:29 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow