1

I need to create DbSet for my ignored entity. Now I have in my modelBuilder next code:

modelBuilder.Ignore<ExtendedDepartment>();

And inside my DbSet I have:

public DbSet<ExtendedDepartment> ExtendedDepartments { get; set; }

When I`m trying to get data from that Dbset I have error:

InvalidOperationException: Cannot create a DbSet for ExtendedDepartment because this type is not included in the model for the context.

So I am trying to ignore this table in migration, maybe I am doing smthing wrong.

6
  • Why did you need to ignore the table in migration? For generating ExtendedDepartments table and access DbSet<ExtendedDepartments >, you should not use modelBuilder.Ignore<ExtendedDepartment>();. If you real want to ignore the migration, you need to modify the generated migration.cs file to remove the code related with ExtendedDepartment. In general, there is no need to because if you did not change anyting in ExtendedDepartment, it would not generate migration for ExtendedDepartment table. If you changed, you should keep the table udpate. Commented Mar 7, 2018 at 10:10
  • This table should be empty. So I dont need it in my db. I wonna use it just to get some data from two tables. So Im using SP for that and I cant do method from EF Include(). I`m trying to find alternative for that. Commented Mar 7, 2018 at 10:20
  • What is "SP'? If the data for ExtendedDepartment is from two tables, there is no need to define DbSet<ExtendedDepartment>in the DbContext, you could query ExtendedDepartment from the two tables. Commented Mar 7, 2018 at 12:09
  • Stored Procedures) Commented Mar 7, 2018 at 21:54
  • Mapping SP to DbSet is not supported currently. Currently, you only could run SP from DbSet by FromSql. You may consider use Entity Framework Core - Mapping Stored Procedures, Fluently to extend DbContext instead of using DbSet<T>. Commented Mar 8, 2018 at 3:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.