C
C#16mo ago
framoz

✅ EF Seeding and Relationships

Hey everyone, I have a quick question. I'm reading through the EF documentation rn because I need to do seeding on my project. It got me a little confused... I have a many to many relationship between a class Person and Film, and I need to do their relation in the objects I'm creating through seeding, but I got a little lost on how to do it because all examples change a part of my code that is needed to create the relation between these objects in the first place (on first image). Is anyone familiar with this to help me? Code Example that changed stuff is on the 2nd pic. If I follow this examples, will the relationships remain the same (and working)? This is the link I was reading from: https://learn.microsoft.com/en-us/ef/core/modeling/relationships?tabs=fluent-api%2Cfluent-api-simple-key%2Csimple-key#joining-relationships-configuration I'll send some photos of my code too (idk how you guys do to post code on text here).
Relationships - EF Core
How to configure relationships between entity types when using Entity Framework Core
3 Replies
Playboi17
Playboi1716mo ago
$code
MODiX
MODiX16mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
framoz
framoz16mo ago
tks """""solved"""" it by manually writing part of the migration. Couldn't find how to do it in a way that wasn't this.
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.InsertData(
table: "FilmPeople",
columns: new[] { "FilmsId", "PeopleId" },
values: new object[,] {
{1,1 },
{1,2 },
{1,3 },
{2,4},
{2,5},
{2,6},
{3,4},
{3,5},
{3,6},
{4,7 },
{4,8},
{4,9},
{5,10},
{5,11},
{5,12},
});
}
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.InsertData(
table: "FilmPeople",
columns: new[] { "FilmsId", "PeopleId" },
values: new object[,] {
{1,1 },
{1,2 },
{1,3 },
{2,4},
{2,5},
{2,6},
{3,4},
{3,5},
{3,6},
{4,7 },
{4,8},
{4,9},
{5,10},
{5,11},
{5,12},
});
}
Want results from more Discord servers?
Add your server
More Posts