.Net core 3.x Keyless Entity Types avoid table creation

后端 未结 1 355
我在风中等你
我在风中等你 2020-12-20 14:39

I need to execute a complex sql query in entity framework core 3.1.1, on researching i found out that keyless entity types is the way to go in code first approach. I see lot

相关标签:
1条回答
  • 2020-12-20 15:20

    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);
    
    0 讨论(0)
提交回复
热议问题