This can include anything from weapons and armor to food and supplies. Inventory is important because it can determine what your character can and cannot do.
今日說明製作角色,有關於一對多資料庫關聯表之API
所持物是指玩家角色身上攜帶的所有物品。這些物品可以是武器、盔甲、食物、藥品、魔法物品等,可以幫助玩家角色在冒險中生存和戰鬥。理所當然,角色可攜帶多種不同的物品,是故在此便可在角色表及所持物間建立一對多關聯,以下為建表,於UserCharacter
處須加上public ICollection<Inventory> Inventory { get; set; }
以代表一對多關聯:
public partial class Inventory
{
[Key]
[Column("CharacterID")]
[ForeignKey("UserCharacters")]
public int Id { get; set; }
[Column("ItemName")]
[MaxLength(30)]
public string Name { get; set; }
[MaxLength(30)]
public string Type { get; set; }
[MaxLength(100)]
public string Description { get; set; }
public int Weight { get; set; }
public int Quantity { get; set; }
public int TotalWeight()
{
return Weight * Quantity;
}
public UserCharacters UserCharacters { get; set; }
}