using System;
using Jellyfin.Server.Implementations.ValueConverters;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Jellyfin.Server.Implementations
{
///
/// Model builder extensions.
///
public static class ModelBuilderExtensions
{
///
/// Specify value converter for the object type.
///
/// The model builder.
/// The .
/// The type to convert.
/// The modified .
public static ModelBuilder UseValueConverterForType(this ModelBuilder modelBuilder, ValueConverter converter)
{
var type = typeof(T);
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
{
foreach (var property in entityType.GetProperties())
{
if (property.ClrType == type)
{
property.SetValueConverter(converter);
}
}
}
return modelBuilder;
}
///
/// Specify the default .
///
/// The model builder to extend.
/// The to specify.
public static void SetDefaultDateTimeKind(this ModelBuilder modelBuilder, DateTimeKind kind)
{
modelBuilder.UseValueConverterForType(new DateTimeKindValueConverter(kind));
modelBuilder.UseValueConverterForType(new DateTimeKindValueConverter(kind));
}
}
}