Preference.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.ComponentModel.DataAnnotations;
  3. using System.ComponentModel.DataAnnotations.Schema;
  4. using Jellyfin.Data.Enums;
  5. using Jellyfin.Data.Interfaces;
  6. namespace Jellyfin.Data.Entities
  7. {
  8. /// <summary>
  9. /// An entity representing a preference attached to a user or group.
  10. /// </summary>
  11. public class Preference : IHasConcurrencyToken
  12. {
  13. /// <summary>
  14. /// Initializes a new instance of the <see cref="Preference"/> class.
  15. /// Public constructor with required data.
  16. /// </summary>
  17. /// <param name="kind">The preference kind.</param>
  18. /// <param name="value">The value.</param>
  19. public Preference(PreferenceKind kind, string value)
  20. {
  21. Kind = kind;
  22. Value = value ?? throw new ArgumentNullException(nameof(value));
  23. }
  24. /// <summary>
  25. /// Initializes a new instance of the <see cref="Preference"/> class.
  26. /// Default constructor. Protected due to required properties, but present because EF needs it.
  27. /// </summary>
  28. protected Preference()
  29. {
  30. }
  31. /// <summary>
  32. /// Gets or sets the id of this preference.
  33. /// </summary>
  34. /// <remarks>
  35. /// Identity, Indexed, Required.
  36. /// </remarks>
  37. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  38. public int Id { get; protected set; }
  39. /// <summary>
  40. /// Gets or sets the type of this preference.
  41. /// </summary>
  42. /// <remarks>
  43. /// Required.
  44. /// </remarks>
  45. public PreferenceKind Kind { get; protected set; }
  46. /// <summary>
  47. /// Gets or sets the value of this preference.
  48. /// </summary>
  49. /// <remarks>
  50. /// Required, Max length = 65535.
  51. /// </remarks>
  52. [Required]
  53. [MaxLength(65535)]
  54. [StringLength(65535)]
  55. public string Value { get; set; }
  56. /// <inheritdoc/>
  57. [ConcurrencyCheck]
  58. public uint RowVersion { get; set; }
  59. /// <inheritdoc/>
  60. public void OnSavingChanges()
  61. {
  62. RowVersion++;
  63. }
  64. }
  65. }