Skip to content

Commit 3190fd1

Browse files
Ticket #894 : Fix warning messages in EF
1 parent c595013 commit 3190fd1

21 files changed

Lines changed: 147 additions & 77 deletions

formbuilder/FormBuilder.EF/Configurations/FormRecordConfiguration.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
33
using FormBuilder.Models;
44
using Microsoft.EntityFrameworkCore;
5+
using Microsoft.EntityFrameworkCore.ChangeTracking;
56
using Microsoft.EntityFrameworkCore.Metadata.Builders;
67
using System.Collections.ObjectModel;
78
using System.Text.Json;
@@ -12,15 +13,26 @@ public class FormRecordConfiguration : IEntityTypeConfiguration<FormRecord>
1213
{
1314
public void Configure(EntityTypeBuilder<FormRecord> builder)
1415
{
16+
var formElementComparer = new ValueComparer<ObservableCollection<IFormElementRecord>>(
17+
(c1, c2) => false,
18+
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v != null && v.Id != null ? v.Id.GetHashCode() : 0)),
19+
c => c == null ? null : new ObservableCollection<IFormElementRecord>(c));
20+
var formMessageTranslationComparer = new ValueComparer<List<FormMessageTranslation>>(
21+
(c1, c2) => false,
22+
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v != null && v.Key != null ? v.Key.GetHashCode() : 0)),
23+
c => c == null ? null : new List<FormMessageTranslation>(c));
1524
builder.HasKey(f => f.Id);
1625
builder.Property(w => w.SuccessMessageTranslations).HasConversion(
1726
v => JsonSerializer.Serialize(v, (JsonSerializerOptions)null),
18-
v => string.IsNullOrWhiteSpace(v) ? null : JsonSerializer.Deserialize<List<FormMessageTranslation>>(v, (JsonSerializerOptions)null));
27+
v => string.IsNullOrWhiteSpace(v) ? null : JsonSerializer.Deserialize<List<FormMessageTranslation>>(v, (JsonSerializerOptions)null))
28+
.Metadata.SetValueComparer(formMessageTranslationComparer);
1929
builder.Property(w => w.ErrorMessageTranslations).HasConversion(
2030
v => JsonSerializer.Serialize(v, (JsonSerializerOptions)null),
21-
v => string.IsNullOrWhiteSpace(v) ? null : JsonSerializer.Deserialize<List<FormMessageTranslation>>(v, (JsonSerializerOptions)null));
31+
v => string.IsNullOrWhiteSpace(v) ? null : JsonSerializer.Deserialize<List<FormMessageTranslation>>(v, (JsonSerializerOptions)null))
32+
.Metadata.SetValueComparer(formMessageTranslationComparer);
2233
builder.Property(w => w.Elements).HasConversion(
2334
v => JsonSerializer.Serialize(v, (JsonSerializerOptions)null),
24-
v => string.IsNullOrWhiteSpace(v) ? null : new ObservableCollection<IFormElementRecord>(JsonSerializer.Deserialize<List<IFormElementRecord>>(v, (JsonSerializerOptions)null)));
35+
v => string.IsNullOrWhiteSpace(v) ? null : new ObservableCollection<IFormElementRecord>(JsonSerializer.Deserialize<List<IFormElementRecord>>(v, (JsonSerializerOptions)null)))
36+
.Metadata.SetValueComparer(formElementComparer);
2537
}
2638
}

formbuilder/FormBuilder.EF/Configurations/TemplateConfiguration.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
33
using FormBuilder.Models;
44
using Microsoft.EntityFrameworkCore;
5+
using Microsoft.EntityFrameworkCore.ChangeTracking;
56
using Microsoft.EntityFrameworkCore.Metadata.Builders;
67
using System.Text.Json;
78

@@ -12,14 +13,29 @@ public class TemplateConfiguration : IEntityTypeConfiguration<Template>
1213
public void Configure(EntityTypeBuilder<Template> builder)
1314
{
1415
builder.HasKey(x => x.Id);
16+
var templateStyleComparer = new ValueComparer<List<TemplateStyle>>(
17+
(c1, c2) => false,
18+
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v != null && v.Id != null ? v.Id.GetHashCode() : 0)),
19+
c => c == null ? null : new List<TemplateStyle>(c));
20+
var templateWindowComparer = new ValueComparer<List<TemplateWindow>>(
21+
(c1, c2) => false,
22+
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v != null && v.Key != null ? v.Key.GetHashCode() : 0)),
23+
c => c == null ? null : new List<TemplateWindow>(c));
24+
var templateElementComparer = new ValueComparer<List<TemplateElement>>(
25+
(c1, c2) => false,
26+
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v != null && v.Key != null ? v.Key.GetHashCode() : 0)),
27+
c => c == null ? null : new List<TemplateElement>(c));
1528
builder.Property(w => w.Styles).HasConversion(
1629
v => JsonSerializer.Serialize(v, (JsonSerializerOptions)null),
17-
v => string.IsNullOrWhiteSpace(v) ? null : new List<TemplateStyle>(JsonSerializer.Deserialize<List<TemplateStyle>>(v, (JsonSerializerOptions)null)));
30+
v => string.IsNullOrWhiteSpace(v) ? null : new List<TemplateStyle>(JsonSerializer.Deserialize<List<TemplateStyle>>(v, (JsonSerializerOptions)null)))
31+
.Metadata.SetValueComparer(templateStyleComparer);
1832
builder.Property(w => w.Windows).HasConversion(
1933
v => JsonSerializer.Serialize(v, (JsonSerializerOptions)null),
20-
v => string.IsNullOrWhiteSpace(v) ? null : new List<TemplateWindow>(JsonSerializer.Deserialize<List<TemplateWindow>>(v, (JsonSerializerOptions)null)));
34+
v => string.IsNullOrWhiteSpace(v) ? null : new List<TemplateWindow>(JsonSerializer.Deserialize<List<TemplateWindow>>(v, (JsonSerializerOptions)null)))
35+
.Metadata.SetValueComparer(templateWindowComparer);
2136
builder.Property(w => w.Elements).HasConversion(
2237
v => JsonSerializer.Serialize(v, (JsonSerializerOptions)null),
23-
v => string.IsNullOrWhiteSpace(v) ? null : new List<TemplateElement>(JsonSerializer.Deserialize<List<TemplateElement>>(v, (JsonSerializerOptions)null)));
38+
v => string.IsNullOrWhiteSpace(v) ? null : new List<TemplateElement>(JsonSerializer.Deserialize<List<TemplateElement>>(v, (JsonSerializerOptions)null)))
39+
.Metadata.SetValueComparer(templateElementComparer);
2440
}
2541
}

formbuilder/FormBuilder.EF/Configurations/WorkflowLinkConfiguration.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
33
using FormBuilder.Models;
44
using Microsoft.EntityFrameworkCore;
5+
using Microsoft.EntityFrameworkCore.ChangeTracking;
56
using Microsoft.EntityFrameworkCore.Metadata.Builders;
67
using System.Text.Json;
78

@@ -11,6 +12,10 @@ public class WorkflowLinkConfiguration : IEntityTypeConfiguration<WorkflowLink>
1112
{
1213
public void Configure(EntityTypeBuilder<WorkflowLink> builder)
1314
{
15+
var workflowLinkTargetComparer = new ValueComparer<List<WorkflowLinkTarget>>(
16+
(c1, c2) => false,
17+
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v != null && v.TargetStepId != null ? v.TargetStepId.GetHashCode() : 0)),
18+
c => c == null ? null : new List<WorkflowLinkTarget>(c));
1419
builder.HasKey(w => w.Id);
1520
builder.Ignore(w => w.IsLinkHoverStep);
1621
builder.Ignore(w => w.IsHover);
@@ -19,6 +24,7 @@ public void Configure(EntityTypeBuilder<WorkflowLink> builder)
1924
v => string.IsNullOrWhiteSpace(v) ? null : JsonSerializer.Deserialize<WorkflowLinkSource>(v, (JsonSerializerOptions)null));
2025
builder.Property(w => w.Targets).HasConversion(
2126
v => JsonSerializer.Serialize(v, (JsonSerializerOptions)null),
22-
v => string.IsNullOrWhiteSpace(v) ? null : JsonSerializer.Deserialize<List<WorkflowLinkTarget>>(v, (JsonSerializerOptions)null));
27+
v => string.IsNullOrWhiteSpace(v) ? null : JsonSerializer.Deserialize<List<WorkflowLinkTarget>>(v, (JsonSerializerOptions)null))
28+
.Metadata.SetValueComparer(workflowLinkTargetComparer);
2329
}
2430
}

formbuilder/FormBuilder/Models/FormMessageTranslation.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,12 @@ public string Value
1616
{
1717
get; set;
1818
}
19+
20+
public string Key
21+
{
22+
get
23+
{
24+
return $"{Language}:{Code}";
25+
}
26+
}
1927
}

formbuilder/FormBuilder/Models/TemplateElement.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,12 @@ public string Value
1616
{
1717
get; set;
1818
}
19+
20+
public string Key
21+
{
22+
get
23+
{
24+
return $"{Element}:{Name}";
25+
}
26+
}
1927
}

src/IdServer/SimpleIdServer.IdServer.Domains/BCAuthorize.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using SimpleIdServer.IdServer.Domains.DTOs;
55
using System.Data;
66
using System.Text;
7-
using System.Text.Json.Serialization;
87
using System.Text.Json;
98

109
namespace SimpleIdServer.IdServer.Domains

src/IdServer/SimpleIdServer.IdServer.Domains/Client.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public string? PolicyUri
137137
/// Array of strings representing ways to contact people responsible for this client, typically email addresses.
138138
/// </summary>
139139
[JsonPropertyName(OAuthClientParameters.Contacts)]
140-
public ICollection<string> Contacts { get; set; } = new List<string>();
140+
public IEnumerable<string> Contacts { get; set; } = new List<string>();
141141
/// <summary>
142142
/// A unique identifier string assigned by the client developer or software publisher used by registration endpoints to identify the client software to be dynamically registered.
143143
/// </summary>

src/IdServer/SimpleIdServer.IdServer.Store.EF/Configurations/AuditEventConfiguration.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
using Microsoft.EntityFrameworkCore;
44
using Microsoft.EntityFrameworkCore.Metadata.Builders;
55
using SimpleIdServer.IdServer.Domains;
6+
using SimpleIdServer.IdServer.Store.EF.Extensions;
67

7-
namespace SimpleIdServer.IdServer.Store.Configurations
8+
namespace SimpleIdServer.IdServer.Store.Configurations;
9+
10+
public class AuditEventConfiguration : IEntityTypeConfiguration<AuditEvent>
811
{
9-
public class AuditEventConfiguration : IEntityTypeConfiguration<AuditEvent>
12+
public void Configure(EntityTypeBuilder<AuditEvent> builder)
1013
{
11-
public void Configure(EntityTypeBuilder<AuditEvent> builder)
12-
{
13-
builder.HasKey(a => a.Id);
14-
builder.Property(a => a.Scopes).HasConversion(v => string.Join(',', v), v => v.Split(",", StringSplitOptions.RemoveEmptyEntries));
15-
builder.Property(a => a.Claims).HasConversion(v => string.Join(',', v), v => v.Split(",", StringSplitOptions.RemoveEmptyEntries));
16-
}
14+
builder.HasKey(a => a.Id);
15+
builder.Property(a => a.Scopes).ConfigureSerializer();
16+
builder.Property(a => a.Claims).ConfigureSerializer();
1717
}
1818
}

src/IdServer/SimpleIdServer.IdServer.Store.EF/Configurations/BCAuthorizeConfiguration.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Microsoft.EntityFrameworkCore;
44
using Microsoft.EntityFrameworkCore.Metadata.Builders;
55
using SimpleIdServer.IdServer.Domains;
6+
using SimpleIdServer.IdServer.Store.EF.Extensions;
67

78
namespace SimpleIdServer.IdServer.Store.Configurations
89
{
@@ -13,9 +14,7 @@ public void Configure(EntityTypeBuilder<BCAuthorize> builder)
1314
builder.HasKey(bc => bc.Id);
1415
builder.Ignore(bc => bc.IsActive);
1516
builder.Ignore(bc => bc.LastHistory);
16-
builder.Property(a => a.Scopes).HasConversion(
17-
v => string.Join(',', v),
18-
v => v.Split(',', StringSplitOptions.None).ToList());
17+
builder.Property(a => a.Scopes).ConfigureSerializer();
1918
builder.HasMany(a => a.Histories).WithOne().OnDelete(DeleteBehavior.Cascade);
2019
builder.Ignore(bc => bc.AuthorizationDetails);
2120
}

src/IdServer/SimpleIdServer.IdServer.Store.EF/Configurations/ClientConfiguration.cs

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Microsoft.EntityFrameworkCore;
44
using Microsoft.EntityFrameworkCore.Metadata.Builders;
55
using SimpleIdServer.IdServer.Domains;
6+
using SimpleIdServer.IdServer.Store.EF.Extensions;
67

78
namespace SimpleIdServer.IdServer.Store.Configurations
89
{
@@ -11,33 +12,15 @@ public class ClientConfiguration : IEntityTypeConfiguration<Client>
1112
public void Configure(EntityTypeBuilder<Client> builder)
1213
{
1314
builder.HasKey(c => c.Id);
14-
builder.Property(a => a.ClientRegistrationTypesSupported).HasConversion(
15-
v => string.Join(',', v),
16-
v => v.Split(',', StringSplitOptions.None).ToList());
17-
builder.Property(a => a.GrantTypes).HasConversion(
18-
v => string.Join(',', v),
19-
v => v.Split(',', StringSplitOptions.None).ToList());
20-
builder.Property(a => a.ResponseTypes).HasConversion(
21-
v => string.Join(',', v),
22-
v => v.Split(',', StringSplitOptions.None).ToList());
23-
builder.Property(a => a.RedirectionUrls).HasConversion(
24-
v => string.Join(',', v),
25-
v => v.Split(',', StringSplitOptions.None).ToList());
26-
builder.Property(a => a.PostLogoutRedirectUris).HasConversion(
27-
v => string.Join(',', v),
28-
v => v.Split(',', StringSplitOptions.None).ToList());
29-
builder.Property(a => a.Contacts).HasConversion(
30-
v => string.Join(',', v),
31-
v => v.Split(',', StringSplitOptions.None).ToList());
32-
builder.Property(a => a.DefaultAcrValues).HasConversion(
33-
v => string.Join(',', v),
34-
v => v.Split(',', StringSplitOptions.None).ToList());
35-
builder.Property(a => a.AuthorizationDataTypes).HasConversion(
36-
v => string.Join(',', v),
37-
v => v.Split(',', StringSplitOptions.None).ToList());
38-
builder.Property(a => a.SubjectSyntaxTypesSupported).HasConversion(
39-
v => string.Join(',', v),
40-
v => v.Split(',', StringSplitOptions.None).ToList());
15+
builder.Property(a => a.ClientRegistrationTypesSupported).ConfigureSerializer();
16+
builder.Property(a => a.GrantTypes).ConfigureSerializer();
17+
builder.Property(a => a.ResponseTypes).ConfigureSerializer();
18+
builder.Property(a => a.RedirectionUrls).ConfigureSerializer();
19+
builder.Property(a => a.PostLogoutRedirectUris).ConfigureSerializer();
20+
builder.Property(a => a.Contacts).ConfigureSerializer();
21+
builder.Property(a => a.DefaultAcrValues).ConfigureSerializer();
22+
builder.Property(a => a.AuthorizationDataTypes).ConfigureSerializer();
23+
builder.Property(a => a.SubjectSyntaxTypesSupported).ConfigureSerializer();
4124
builder.HasMany(c => c.Translations).WithOne().OnDelete(DeleteBehavior.Cascade);
4225
builder.HasMany(c => c.SerializedJsonWebKeys).WithOne().OnDelete(DeleteBehavior.Cascade);
4326
builder.HasMany(c => c.DeviceAuthCodes).WithOne(a => a.Client).OnDelete(DeleteBehavior.Cascade);

0 commit comments

Comments
 (0)