< Summary - Jellyfin

Information
Class: Jellyfin.Database.Providers.Sqlite.ModelBuilderExtensions
Assembly: Jellyfin.Database.Providers.Sqlite
File(s): /srv/git/jellyfin/src/Jellyfin.Database/Jellyfin.Database.Providers.Sqlite/ModelBuilderExtensions.cs
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
Total lines: 47
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
UseValueConverterForType(...)100%66100%
SetDefaultDateTimeKind(...)100%11100%

File(s)

/srv/git/jellyfin/src/Jellyfin.Database/Jellyfin.Database.Providers.Sqlite/ModelBuilderExtensions.cs

#LineLine coverage
 1using System;
 2using Jellyfin.Database.Providers.Sqlite.ValueConverters;
 3using Microsoft.EntityFrameworkCore;
 4using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
 5
 6namespace Jellyfin.Database.Providers.Sqlite;
 7
 8/// <summary>
 9/// Model builder extensions.
 10/// </summary>
 11public static class ModelBuilderExtensions
 12{
 13    /// <summary>
 14    /// Specify value converter for the object type.
 15    /// </summary>
 16    /// <param name="modelBuilder">The model builder.</param>
 17    /// <param name="converter">The <see cref="ValueConverter{TModel,TProvider}"/>.</param>
 18    /// <typeparam name="T">The type to convert.</typeparam>
 19    /// <returns>The modified <see cref="ModelBuilder"/>.</returns>
 20    public static ModelBuilder UseValueConverterForType<T>(this ModelBuilder modelBuilder, ValueConverter converter)
 21    {
 422        var type = typeof(T);
 24023        foreach (var entityType in modelBuilder.Model.GetEntityTypes())
 24        {
 265625            foreach (var property in entityType.GetProperties())
 26            {
 121227                if (property.ClrType == type)
 28                {
 4029                    property.SetValueConverter(converter);
 30                }
 31            }
 32        }
 33
 434        return modelBuilder;
 35    }
 36
 37    /// <summary>
 38    /// Specify the default <see cref="DateTimeKind"/>.
 39    /// </summary>
 40    /// <param name="modelBuilder">The model builder to extend.</param>
 41    /// <param name="kind">The <see cref="DateTimeKind"/> to specify.</param>
 42    public static void SetDefaultDateTimeKind(this ModelBuilder modelBuilder, DateTimeKind kind)
 43    {
 244        modelBuilder.UseValueConverterForType<DateTime>(new DateTimeKindValueConverter(kind));
 245        modelBuilder.UseValueConverterForType<DateTime?>(new DateTimeKindValueConverter(kind));
 246    }
 47}