dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.6k stars 25.29k forks source link

Container issue for EF/MVC #17465

Open AucT opened 4 years ago

AucT commented 4 years ago

This is the container issue for this doc. Reopen each issue you are working on so the owner is notified.

Before any of these issues are fixed, we'll do #26505, which will resolve many of the following issues.


Відомості про документ

Не змінюйте цей розділ. Він необхідний для зв’язування питань на платформах docs.microsoft.com ➟ GitHub.

Rick-Anderson commented 4 years ago

Update edit for container

mima89 commented 4 years ago

I was also getting the same error when I tried to create migration. I removed modelBuilder.Entity().ToTable("Instructor"); and modelBuilder.Entity().ToTable("Student"); from OnModelCreating method in context class and now it is working. I found the solution her https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.0/breaking-changes#totable-on-a-derived-type-throws-an-exception.

Funix565 commented 2 years ago

Hi, My application also didn't run when I completed the inheritance part. I've changed the table name to Person in SchoolContext.cs

modelBuilder.Entity<Student>().ToTable("Person"); // <-- modelBuilder.Entity<Student>().ToTable("Student"); 

// and

modelBuilder.Entity<Instructor>().ToTable("Person"); // <-- modelBuilder.Entity<Instructor>().ToTable("Instructor");

We can see the same code in the completed application on GitHub. This issue is reported in #22828, #22047, #20671

Funix565 commented 2 years ago

As for the #21783, FromSql should be FromSqlRaw in DepartmentsController.cs

var department = await _context.Departments
                .FromSqlRaw(query, id)
                .Include(d = > d.Administrator)
                .AsNoTracking()
                .FirstOrDefaultAsync();

The merge to the docs was approved in #23398. The changes are described in this article https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.x/breaking-changes#fromsql. Tracking issue https://github.com/dotnet/efcore/issues/10996

Funix565 commented 2 years ago

Dear @Rick-Anderson ,

Could you please explain to me the purpose of this container issue? As I see, they are all closed with almost no solution or explanation provided.

The latest commit to the EF Core with MVC repository was done on Jun 24, 2022. So I think it would be still relevant to adjust some code snippets which misled me and may confuse other users too.

Now there are 4 directories related to this tutorial. It would be great to know what they are for so I could make the necessary edits.

Here is my plan:

modelBuilder.Entity<Student>().ToTable("Person");
modelBuilder.Entity<Instructor>().ToTable("Person");

Or should we remove these lines at all? https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/data/ef-mvc/intro/samples/cu/Data/SchoolContext.cs#L113 https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/data/ef-mvc/intro/samples/cu/Data/SchoolContext.cs#L115

Then we should also rephrase the action phrase to something like that: https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/data/ef-mvc/inheritance.md?plain=1#L84

Add the Person entity type to SchoolContext.cs and specify the new names for Student and Instructor tables since they are now joined into one table Person. The new lines are highlighted.

OR

Add the Person entity type to SchoolContext.cs and remove the unnecessary table name mappings for the Student and Instructor since these tables are now joined into one table Person.

What do you think?

Rick-Anderson commented 2 years ago

@Funix565

Could you please explain to me the purpose of this container issue?

We don't have the resources to working on issues for this document, so we are keeping one container issue to track all the issues we'd like to fix.

The entire doc needs to be updated using much of the code from Razor Pages with Entity Framework Core

Rick-Anderson commented 2 years ago

See #26505