CollectionItem.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using System;
  2. using System.ComponentModel.DataAnnotations;
  3. using System.ComponentModel.DataAnnotations.Schema;
  4. namespace Jellyfin.Data.Entities
  5. {
  6. public partial class CollectionItem
  7. {
  8. partial void Init();
  9. /// <summary>
  10. /// Default constructor. Protected due to required properties, but present because EF needs it.
  11. /// </summary>
  12. protected CollectionItem()
  13. {
  14. // NOTE: This class has one-to-one associations with CollectionItem.
  15. // One-to-one associations are not validated in constructors since this causes a scenario where each one must be constructed before the other.
  16. Init();
  17. }
  18. /// <summary>
  19. /// Replaces default constructor, since it's protected. Caller assumes responsibility for setting all required values before saving.
  20. /// </summary>
  21. public static CollectionItem CreateCollectionItemUnsafe()
  22. {
  23. return new CollectionItem();
  24. }
  25. /// <summary>
  26. /// Public constructor with required data
  27. /// </summary>
  28. /// <param name="_collection0"></param>
  29. /// <param name="_collectionitem1"></param>
  30. /// <param name="_collectionitem2"></param>
  31. public CollectionItem(Collection _collection0, CollectionItem _collectionitem1, CollectionItem _collectionitem2)
  32. {
  33. // NOTE: This class has one-to-one associations with CollectionItem.
  34. // One-to-one associations are not validated in constructors since this causes a scenario where each one must be constructed before the other.
  35. if (_collection0 == null) throw new ArgumentNullException(nameof(_collection0));
  36. _collection0.CollectionItem.Add(this);
  37. if (_collectionitem1 == null) throw new ArgumentNullException(nameof(_collectionitem1));
  38. _collectionitem1.Next = this;
  39. if (_collectionitem2 == null) throw new ArgumentNullException(nameof(_collectionitem2));
  40. _collectionitem2.Previous = this;
  41. Init();
  42. }
  43. /// <summary>
  44. /// Static create function (for use in LINQ queries, etc.)
  45. /// </summary>
  46. /// <param name="_collection0"></param>
  47. /// <param name="_collectionitem1"></param>
  48. /// <param name="_collectionitem2"></param>
  49. public static CollectionItem Create(Collection _collection0, CollectionItem _collectionitem1, CollectionItem _collectionitem2)
  50. {
  51. return new CollectionItem(_collection0, _collectionitem1, _collectionitem2);
  52. }
  53. /*************************************************************************
  54. * Properties
  55. *************************************************************************/
  56. /// <summary>
  57. /// Backing field for Id
  58. /// </summary>
  59. internal int _Id;
  60. /// <summary>
  61. /// When provided in a partial class, allows value of Id to be changed before setting.
  62. /// </summary>
  63. partial void SetId(int oldValue, ref int newValue);
  64. /// <summary>
  65. /// When provided in a partial class, allows value of Id to be changed before returning.
  66. /// </summary>
  67. partial void GetId(ref int result);
  68. /// <summary>
  69. /// Identity, Indexed, Required
  70. /// </summary>
  71. [Key]
  72. [Required]
  73. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  74. public int Id
  75. {
  76. get
  77. {
  78. int value = _Id;
  79. GetId(ref value);
  80. return (_Id = value);
  81. }
  82. protected set
  83. {
  84. int oldValue = _Id;
  85. SetId(oldValue, ref value);
  86. if (oldValue != value)
  87. {
  88. _Id = value;
  89. }
  90. }
  91. }
  92. /// <summary>
  93. /// Required, ConcurrenyToken
  94. /// </summary>
  95. [ConcurrencyCheck]
  96. [Required]
  97. public uint RowVersion { get; set; }
  98. public void OnSavingChanges()
  99. {
  100. RowVersion++;
  101. }
  102. /*************************************************************************
  103. * Navigation properties
  104. *************************************************************************/
  105. /// <summary>
  106. /// Required
  107. /// </summary>
  108. [ForeignKey("LibraryItem_Id")]
  109. public virtual LibraryItem LibraryItem { get; set; }
  110. /// <remarks>
  111. /// TODO check if this properly updated dependant and has the proper principal relationship
  112. /// </remarks>
  113. [ForeignKey("CollectionItem_Next_Id")]
  114. public virtual CollectionItem Next { get; set; }
  115. /// <remarks>
  116. /// TODO check if this properly updated dependant and has the proper principal relationship
  117. /// </remarks>
  118. [ForeignKey("CollectionItem_Previous_Id")]
  119. public virtual CollectionItem Previous { get; set; }
  120. }
  121. }