mirror of
				https://github.com/Kareadita/Kavita.git
				synced 2025-10-31 10:37:04 -04:00 
			
		
		
		
	
		
			
				
	
	
		
			18 lines
		
	
	
		
			529 B
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			18 lines
		
	
	
		
			529 B
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System.Text.Json;
 | |
| using Microsoft.EntityFrameworkCore.Metadata.Builders;
 | |
| 
 | |
| namespace API.Extensions;
 | |
| 
 | |
| public static class DataContextExtensions
 | |
| {
 | |
| 
 | |
|     public static PropertyBuilder<TProperty> HasJsonConversion<TProperty>(this PropertyBuilder<TProperty> builder, TProperty def = default)
 | |
|     {
 | |
|         return builder.HasConversion(
 | |
|             v => JsonSerializer.Serialize(v, JsonSerializerOptions.Default),
 | |
|             v => JsonSerializer.Deserialize<TProperty>(v, JsonSerializerOptions.Default) ?? def
 | |
|         );
 | |
|     }
 | |
| 
 | |
| }
 |