C#C
C#2y ago
PIE

✅ List<KeyValuePair<Trader, long>> requires primary key to be defined

This is my main model i'm trying to pass

public class Item
{
    [Key]
    public int Id { get; set; }
    public string Name { get; set; }
    public List<KeyValuePair<Trader, long>> TraderPrices { get; set; }
}

with Trader as
[Keyless]
public class Trader
{
    public int Id { get; set; }
    public string Name { get; set; }
    public bool IsTeTrader { get; set; }
    public bool IsAwTrader { get; set; }
}

with a basic database
class ItemDb : DbContext
{
    public ItemDb(DbContextOptions<ItemDb> options)
        : base(options) { }
    
    public DbSet<Item> Items => Set<Item>();
}


for some reason, passing a Item class through this this method
db.Items.Add(itemInput);
await db.SaveChangesAsync();
return Results.Created($"/items/{itemInput.Id}", itemInput);

throws the error in the title
is there a way to set List<KeyValuePair<Trader, long>> to be keyless?
Was this page helpful?