iT邦幫忙

2023 iThome 鐵人賽

DAY 17
0
Cloud Native

The Journey of ASP.NET and Beyond系列 第 17

Web API Practice: Character Sheet API II

  • 分享至 

  • xImage
  •  

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

所持物 Inventory


  所持物是指玩家角色身上攜帶的所有物品。這些物品可以是武器、盔甲、食物、藥品、魔法物品等,可以幫助玩家角色在冒險中生存和戰鬥。理所當然,角色可攜帶多種不同的物品,是故在此便可在角色表及所持物間建立一對多關聯,以下為建表,於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; }

}

上一篇
Almost Swamped by The Job...
下一篇
Web API Practice: Character Sheet API III
系列文
The Journey of ASP.NET and Beyond30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言