0

I have an entity for which I don't want a table. The entity is used to generate a report and is populated using a SQL query:

    public IEnumerable<Entities.MembersReportRow> Get()
    {
         return _context.MembersReportRows
               .FromSqlRaw(@"
                  SELECT...")
               .ToList();
    }

Using modelBuilder.Ignore<MembersReportRow>(); stops the code for creating the table from being added to the migration, but then the method above stops working with error:

Cannot create a DbSet for 'MembersReportRow' because this type is not included in the model for the context.

I've also tried:

        modelBuilder.
            .HasNoKey()
            .ToSqlQuery(@"
                        SELECT...
                    ");

...but the code to create the table still gets created in the migration, which surprises me a little as I'm specifically stating "ToSqlQuery".

Any help would be appreciated!

MountainShack
  • 41
  • 1
  • 1
  • 6
  • Does this answer your question? [How to exclude one table from automatic code first migrations in the Entity Framework?](https://stackoverflow.com/questions/22038924/how-to-exclude-one-table-from-automatic-code-first-migrations-in-the-entity-fram) – Svyatoslav Danyliv Jan 24 '23 at 21:19
  • Yes, that has done the trick. Thanks for the help! – MountainShack Jan 25 '23 at 19:36

0 Answers0