You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a database with the Main and Details tables. The Blog table depends on Main. All this is reflected in the EF entities.
I want to combine the Main and Details entities without changing the database structure. I use SplitToTable for this. But after creating the migration, the foreign key: FK_Blog_Main_MainId is deleted and FK_Blog_Details_MainId is created instead.
public class Main
{
public int Id { get; set; }
public string? Name { get; set; }
public virtual Details? Details { get; set; }
public Blog? Blog { get; set; }
}
public class Details
{
public int Id { get; set; }
public string? Description { get; set; }
}
public class Blog
{
public int Id { get; set; }
public string? Name { get; set; }
public int? MainId { get; set; }
public virtual Main? Main { get; set; }
}
public class Main
{
public int Id { get; set; }
public string? Name { get; set; }
// public virtual Details? Details { get; set; }
public Blog? Blog { get; set; }
#region Details
public string? Description { get; set; }
#endregion
}
Problem
I have a database with the
Main
andDetails
tables. TheBlog
table depends onMain
. All this is reflected in the EF entities.I want to combine the
Main
andDetails
entities without changing the database structure. I useSplitToTable
for this. But after creating the migration, the foreign key:FK_Blog_Main_MainId
is deleted andFK_Blog_Details_MainId
is created instead.Code
https://github.com/AndreqGav/efcore.example.split-to-table
At first, the entities look like this:
EF Configuration:
After using
SplitToTable
The
Details
class has been deletedEF Configuration:
After migration
Include provider and version information
EF Core version:
Database provider: (e.g. Microsoft.EntityFrameworkCore.PostgreSQL)
Target framework: (e.g. .NET 9.0)
The text was updated successfully, but these errors were encountered: