Open AucT opened 4 years ago
Update edit for container
I was also getting the same error when I tried to create migration. I removed modelBuilder.Entity
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
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
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:
[ ] https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/advanced?view=aspnetcore-6.0#call-a-query-to-return-entities
Here we have FromSql
which was renamed to FromRawSql
.
According to the md file of this page ( https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/data/ef-mvc/advanced.md?plain=1#L51 ), I should edit intro/samples/cu/Controllers/DepartmentsController.cs?name=snippet_RawSQL&highlight=8,9,10
This line:
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/data/ef-mvc/intro/samples/cu/Controllers/DepartmentsController.cs#L64
[ ] https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/advanced?view=aspnetcore-6.0#call-an-update-query
Here we have ExecuteSqlCommandAsync
which was renamed to ExecuteSqlRawAsync
.
According to https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/data/ef-mvc/advanced.md?plain=1#L83, I should edit intro/samples/cu/Controllers/CoursesController.cs?name=snippet_UpdatePost
This line:
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/data/ef-mvc/intro/samples/cu/Controllers/CoursesController.cs#L211
[ ] https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/inheritance?view=aspnetcore-6.0#add-person-to-the-model
Here we still have <Student>
and <Instructor>
mapped to their tables. But they don't exist in the database, because we joined these two tables into one table Person
.
According to the md file of this page ( https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/data/ef-mvc/inheritance.md?plain=1#L86 ), I should edit intro/samples/cu/Data/SchoolContext.cs?name=snippet_AfterInheritance&highlight=19,30
According to the final version, we should have
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 toSchoolContext.cs
and specify the new names forStudent
andInstructor
tables since they are now joined into one tablePerson
. The new lines are highlighted.
OR
Add the
Person
entity type toSchoolContext.cs
and remove the unnecessary table name mappings for theStudent
andInstructor
since these tables are now joined into one tablePerson
.
What do you think?
@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
See #26505
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.