mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-22 16:54:46 +03:00
Migrate User DB to EF Core
This commit is contained in:
@@ -1,63 +1,33 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Jellyfin.Data.Enums;
|
||||
|
||||
namespace Jellyfin.Data.Entities
|
||||
{
|
||||
public partial class Preference
|
||||
/// <summary>
|
||||
/// An entity representing a preference attached to a user or group.
|
||||
/// </summary>
|
||||
public class Preference : ISavingChanges
|
||||
{
|
||||
partial void Init();
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Preference"/> class.
|
||||
/// Public constructor with required data.
|
||||
/// </summary>
|
||||
/// <param name="kind">The preference kind.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
public Preference(PreferenceKind kind, string value)
|
||||
{
|
||||
Kind = kind;
|
||||
Value = value ?? throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Preference"/> class.
|
||||
/// Default constructor. Protected due to required properties, but present because EF needs it.
|
||||
/// </summary>
|
||||
protected Preference()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces default constructor, since it's protected. Caller assumes responsibility for setting all required values before saving.
|
||||
/// </summary>
|
||||
public static Preference CreatePreferenceUnsafe()
|
||||
{
|
||||
return new Preference();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Public constructor with required data
|
||||
/// </summary>
|
||||
/// <param name="kind"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="_user0"></param>
|
||||
/// <param name="_group1"></param>
|
||||
public Preference(Enums.PreferenceKind kind, string value, User _user0, Group _group1)
|
||||
{
|
||||
this.Kind = kind;
|
||||
|
||||
if (string.IsNullOrEmpty(value)) throw new ArgumentNullException(nameof(value));
|
||||
this.Value = value;
|
||||
|
||||
if (_user0 == null) throw new ArgumentNullException(nameof(_user0));
|
||||
_user0.Preferences.Add(this);
|
||||
|
||||
if (_group1 == null) throw new ArgumentNullException(nameof(_group1));
|
||||
_group1.Preferences.Add(this);
|
||||
|
||||
|
||||
Init();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Static create function (for use in LINQ queries, etc.)
|
||||
/// </summary>
|
||||
/// <param name="kind"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="_user0"></param>
|
||||
/// <param name="_group1"></param>
|
||||
public static Preference Create(Enums.PreferenceKind kind, string value, User _user0, Group _group1)
|
||||
{
|
||||
return new Preference(kind, value, _user0, _group1);
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
@@ -76,7 +46,7 @@ namespace Jellyfin.Data.Entities
|
||||
/// Required
|
||||
/// </summary>
|
||||
[Required]
|
||||
public Enums.PreferenceKind Kind { get; set; }
|
||||
public PreferenceKind Kind { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Required, Max length = 65535
|
||||
@@ -87,21 +57,28 @@ namespace Jellyfin.Data.Entities
|
||||
public string Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Required, ConcurrenyToken
|
||||
/// Required, ConcurrencyToken.
|
||||
/// </summary>
|
||||
[ConcurrencyCheck]
|
||||
[Required]
|
||||
public uint RowVersion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Static create function (for use in LINQ queries, etc.)
|
||||
/// </summary>
|
||||
/// <param name="kind">The preference kind.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The new instance.</returns>
|
||||
public static Preference Create(PreferenceKind kind, string value)
|
||||
{
|
||||
return new Preference(kind, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void OnSavingChanges()
|
||||
{
|
||||
RowVersion++;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* Navigation properties
|
||||
*************************************************************************/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user