hoofedear
hoofedear
CC#
Created by hoofedear on 12/18/2022 in #help
✅ I want to get duplicate items in my List (EF Core)
49 replies
CC#
Created by hoofedear on 12/18/2022 in #help
✅ I want to get duplicate items in my List (EF Core)
49 replies
CC#
Created by hoofedear on 12/18/2022 in #help
✅ I want to get duplicate items in my List (EF Core)
*without just the j.PrimaryKey part, I did add the j.HasKey part
49 replies
CC#
Created by hoofedear on 12/18/2022 in #help
✅ I want to get duplicate items in my List (EF Core)
So I tried it out without that section and I got this error after trying to save data to the database:
System.InvalidOperationException: The value of 'DeckContent.CardId' is unknown when attempting to save changes. This is because the property is also part of a foreign key for which the principal entity in the relationship is not known.
System.InvalidOperationException: The value of 'DeckContent.CardId' is unknown when attempting to save changes. This is because the property is also part of a foreign key for which the principal entity in the relationship is not known.
49 replies
CC#
Created by hoofedear on 12/18/2022 in #help
✅ I want to get duplicate items in my List (EF Core)
The only part of this that doesn't work is this section:
j => {
j.PrimaryKey(cid => cid.Guid);
j.HasKey(cid => new { cid.CardId, cid.DeckId });
}
j => {
j.PrimaryKey(cid => cid.Guid);
j.HasKey(cid => new { cid.CardId, cid.DeckId });
}
It's saying that it can't resolve symbol PrimaryKey, like it isn't a valid part of j
49 replies
CC#
Created by hoofedear on 12/18/2022 in #help
✅ I want to get duplicate items in my List (EF Core)
I’ll try that! Thanks!
49 replies
CC#
Created by hoofedear on 12/18/2022 in #help
✅ I want to get duplicate items in my List (EF Core)
If it helps, I’m working with Magic the Gathering cards, so imagine many decks with many cards, even duplicates of the same card
49 replies
CC#
Created by hoofedear on 12/18/2022 in #help
✅ I want to get duplicate items in my List (EF Core)
Or is that one-to-many? 😵‍💫
49 replies
CC#
Created by hoofedear on 12/18/2022 in #help
✅ I want to get duplicate items in my List (EF Core)
Because any number of decks can have any number of cards
49 replies
CC#
Created by hoofedear on 12/18/2022 in #help
✅ I want to get duplicate items in my List (EF Core)
Ahhh okay so I do want many to many, hm
49 replies
CC#
Created by hoofedear on 12/18/2022 in #help
✅ I want to get duplicate items in my List (EF Core)
This is from my seeder, and it's a list of 20 cards, but when I retrieve the list of Cards from the database, it only returns 14
49 replies
CC#
Created by hoofedear on 12/18/2022 in #help
✅ I want to get duplicate items in my List (EF Core)
var cardIds = new List<string>
{
"F48B3F46-0E62-4F44-8064-857CD3040659",
"8435C03C-B9A2-40FA-A979-879BD120A011",
"41AC2C18-A26B-4683-B326-97F0E75B4F2A",
"d99a9a7d-d9ca-4c11-80ab-e39d5943a315",
"AC7BA3F5-3AD5-47E7-86C9-31954F015B91",
"46F4AE10-A3DA-4D4F-8706-87CCB076C1F2",
"069B3C69-EE4C-4FC9-981E-62DB77F9821D",
"3AF09CFD-1DD1-45A8-869B-B21BCB03F7CE",
"5E6F3C49-DBFA-4EAB-A561-656E74266834",
"4E9A34A4-2F2C-4C9C-A8D4-73953B62E189",
"7C337AF5-35BF-4A80-8CC0-BB9AF20305B3",
"E48E23FE-F0ED-4C5A-B90B-30CF096A9D02",
"5C3593AA-E33C-4482-A0BB-C843AC70A824",
"52C79D57-A8EB-427D-86AC-B203C0BB7CDA",
"52C79D57-A8EB-427D-86AC-B203C0BB7CDA",
"52C79D57-A8EB-427D-86AC-B203C0BB7CDA",
"52C79D57-A8EB-427D-86AC-B203C0BB7CDA",
"52C79D57-A8EB-427D-86AC-B203C0BB7CDA",
"52C79D57-A8EB-427D-86AC-B203C0BB7CDA",
"52C79D57-A8EB-427D-86AC-B203C0BB7CDA"
};

var cards = await context.Cards.ToListAsync();

var deckList = new List<Card>();

foreach (var id in cardIds)
{
var c = cards.FirstOrDefault(i => string.Equals(i.Id.ToString(), id, StringComparison.OrdinalIgnoreCase));
if (c != null) deckList.Add(c);
else
{
Console.WriteLine("Unable to find card.");
}
}
var cardIds = new List<string>
{
"F48B3F46-0E62-4F44-8064-857CD3040659",
"8435C03C-B9A2-40FA-A979-879BD120A011",
"41AC2C18-A26B-4683-B326-97F0E75B4F2A",
"d99a9a7d-d9ca-4c11-80ab-e39d5943a315",
"AC7BA3F5-3AD5-47E7-86C9-31954F015B91",
"46F4AE10-A3DA-4D4F-8706-87CCB076C1F2",
"069B3C69-EE4C-4FC9-981E-62DB77F9821D",
"3AF09CFD-1DD1-45A8-869B-B21BCB03F7CE",
"5E6F3C49-DBFA-4EAB-A561-656E74266834",
"4E9A34A4-2F2C-4C9C-A8D4-73953B62E189",
"7C337AF5-35BF-4A80-8CC0-BB9AF20305B3",
"E48E23FE-F0ED-4C5A-B90B-30CF096A9D02",
"5C3593AA-E33C-4482-A0BB-C843AC70A824",
"52C79D57-A8EB-427D-86AC-B203C0BB7CDA",
"52C79D57-A8EB-427D-86AC-B203C0BB7CDA",
"52C79D57-A8EB-427D-86AC-B203C0BB7CDA",
"52C79D57-A8EB-427D-86AC-B203C0BB7CDA",
"52C79D57-A8EB-427D-86AC-B203C0BB7CDA",
"52C79D57-A8EB-427D-86AC-B203C0BB7CDA",
"52C79D57-A8EB-427D-86AC-B203C0BB7CDA"
};

var cards = await context.Cards.ToListAsync();

var deckList = new List<Card>();

foreach (var id in cardIds)
{
var c = cards.FirstOrDefault(i => string.Equals(i.Id.ToString(), id, StringComparison.OrdinalIgnoreCase));
if (c != null) deckList.Add(c);
else
{
Console.WriteLine("Unable to find card.");
}
}
49 replies
CC#
Created by hoofedear on 12/18/2022 in #help
✅ I want to get duplicate items in my List (EF Core)
I got it working how I want, where it returns a List of Cards, but it's still omitting duplicate Cards ://
49 replies
CC#
Created by hoofedear on 12/18/2022 in #help
✅ I want to get duplicate items in my List (EF Core)
I think I'm actually going for a one-to-many, and I did remove the virtual haha
49 replies
CC#
Created by hoofedear on 12/18/2022 in #help
✅ I want to get duplicate items in my List (EF Core)
Inside of DeckContent class: public virtual List<Card> DeckList { get; set; } Inside of ApplicationDbContext class builder: builder.Entity<DeckContent>().HasMany(i => i.DeckList).WithMany();
49 replies
CC#
Created by hoofedear on 12/18/2022 in #help
✅ I want to get duplicate items in my List (EF Core)
Is that the only list I need? Or do I need to put something in the Card class to relate them?
49 replies
CC#
Created by hoofedear on 12/18/2022 in #help
✅ I want to get duplicate items in my List (EF Core)
Hm okay so what I have so far is a List<Card> inside of my DeckContents class, with the DeckId as the Key. Is that right? Because a Deck has the details of the Deck (Name, description, Owner) and DeckContents is purely for keeping track of what Cards are in the Deck
49 replies
CC#
Created by hoofedear on 12/18/2022 in #help
✅ I want to get duplicate items in my List (EF Core)
😳 that’s so cool. I’ll look into that, thanks!
49 replies
CC#
Created by hoofedear on 12/18/2022 in #help
✅ I want to get duplicate items in my List (EF Core)
Thanks for the tip! And could you explain the idea of not using IDs? What I have is a table called DeckContents and it’s basically a M-M relation of DeckIDs and CardIDs, so what I do is when I pull the deckList, I get all CardIDs that match the DeckID I’m grabbing. Is there a better way?
49 replies
CC#
Created by hoofedear on 12/18/2022 in #help
✅ I want to get duplicate items in my List (EF Core)
Ah okay I see, I did try a join before but it returned 0 cards but I bet my logic was messed up. I’ll look into that, thank you!
49 replies