Skip to content

Commit f8096d1

Browse files
committed
enable nullable support
1 parent 111e6c7 commit f8096d1

File tree

89 files changed

+794
-614
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+794
-614
lines changed

.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ indent_style = space
99
indent_size = 4
1010
insert_final_newline = true
1111
trim_trailing_whitespace = true
12+
vsspell_section_id = 41b65011239a40959ccaae2a4ec7044a
13+
vsspell_ignored_words_41b65011239a40959ccaae2a4ec7044a = accessor|awaitable|app|clr|inline|middleware|mvc|validator|deconstruct|nullable|serializer|deserializer|serialization|deserialization|queryable
1214

1315
# XML Configuration Files
1416
[*.{xml,config,props,targets,nuspec,resx,ruleset,vsixmanifest,vsct,refactorlog,runsettings}]

sample/Tracker/Tracker.Core/Tracker.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PackageReference Include="AutoMapper" Version="14.0.0" />
1111
<PackageReference Include="FluentValidation" Version="12.0.0" />
1212
<PackageReference Include="Injectio" Version="5.0.0" PrivateAssets="all" />
13-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.4" />
13+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.5" />
1414
</ItemGroup>
1515

1616
<ItemGroup>

sample/Tracker/Tracker.Database/Tracker.Database.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
<ItemGroup>
1818
<PackageReference Include="dbup-sqlserver" Version="6.0.0" />
19-
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.4" />
20-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.4" />
19+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.5" />
20+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.5" />
2121
</ItemGroup>
2222

2323
<ItemGroup>

sample/Tracker/Tracker.Scaffold/Tracker.Scaffold.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.4">
11+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.5">
1212
<PrivateAssets>all</PrivateAssets>
1313
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1414
</PackageReference>
15-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.4" />
15+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.5" />
1616
</ItemGroup>
1717

1818
</Project>

src/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<DefaultLanguage>en-US</DefaultLanguage>
3131
<LangVersion>latest</LangVersion>
3232
<ImplicitUsings>enable</ImplicitUsings>
33+
<Nullable>enable</Nullable>
3334
<NoWarn>1591</NoWarn>
3435
</PropertyGroup>
3536

src/EntityFrameworkCore.Generator.Core/CodeGenerator.cs

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public CodeGenerator(ILoggerFactory loggerFactory)
3030
_synchronizer = new SourceSynchronizer(loggerFactory);
3131
}
3232

33-
public GeneratorOptions Options { get; set; }
33+
public GeneratorOptions Options { get; set; } = null!;
3434

3535
public bool Generate(GeneratorOptions options)
3636
{
@@ -73,13 +73,14 @@ private void GenerateQueryExtensions(EntityContext entityContext)
7373
{
7474
Options.Variables.Set(entity);
7575

76-
var directory = Options.Data.Query.Directory;
76+
var directory = Options.Data.Query.Directory ?? "Data\\Queries";
7777
var file = entity.EntityClass + "Extensions.cs";
7878
var path = Path.Combine(directory, file);
7979

80-
_logger.LogInformation(File.Exists(path)
81-
? "Updating query extensions class: {file}"
82-
: "Creating query extensions class: {file}", file);
80+
if (File.Exists(path))
81+
_logger.LogInformation("Updating query extensions class: {file}", file);
82+
else
83+
_logger.LogInformation("Creating query extensions class: {file}", file);
8384

8485
var template = new QueryExtensionTemplate(entity, Options);
8586
template.WriteCode(path);
@@ -94,13 +95,14 @@ private void GenerateMappingClasses(EntityContext entityContext)
9495
{
9596
Options.Variables.Set(entity);
9697

97-
var directory = Options.Data.Mapping.Directory;
98+
var directory = Options.Data.Mapping.Directory ?? "Data\\Mapping";
9899
var file = entity.MappingClass + ".cs";
99100
var path = Path.Combine(directory, file);
100101

101-
_logger.LogInformation(File.Exists(path)
102-
? "Updating mapping class: {file}"
103-
: "Creating mapping class: {file}", file);
102+
if (File.Exists(path))
103+
_logger.LogInformation("Updating mapping class: {file}", file);
104+
else
105+
_logger.LogInformation("Creating mapping class: {file}", file);
104106

105107
var template = new MappingClassTemplate(entity, Options);
106108
template.WriteCode(path);
@@ -115,13 +117,14 @@ private void GenerateEntityClasses(EntityContext entityContext)
115117
{
116118
Options.Variables.Set(entity);
117119

118-
var directory = Options.Data.Entity.Directory;
120+
var directory = Options.Data.Entity.Directory ?? "Data\\Entities";
119121
var file = entity.EntityClass + ".cs";
120122
var path = Path.Combine(directory, file);
121123

122-
_logger.LogInformation(File.Exists(path)
123-
? "Updating entity class: {file}"
124-
: "Creating entity class: {file}", file);
124+
if (File.Exists(path))
125+
_logger.LogInformation("Updating entity class: {file}", file);
126+
else
127+
_logger.LogInformation("Creating entity class: {file}", file);
125128

126129
var template = new EntityClassTemplate(entity, Options);
127130
template.WriteCode(path);
@@ -133,13 +136,14 @@ private void GenerateEntityClasses(EntityContext entityContext)
133136
private void GenerateDataContext(EntityContext entityContext)
134137
{
135138

136-
var directory = Options.Data.Context.Directory;
139+
var directory = Options.Data.Context.Directory ?? "Data";
137140
var file = entityContext.ContextClass + ".cs";
138141
var path = Path.Combine(directory, file);
139142

140-
_logger.LogInformation(File.Exists(path)
141-
? "Updating data context class: {file}"
142-
: "Creating data context class: {file}", file);
143+
if (File.Exists(path))
144+
_logger.LogInformation("Updating data context class: {file}", file);
145+
else
146+
_logger.LogInformation("Creating data context class: {file}", file);
143147

144148
var template = new DataContextTemplate(entityContext, Options);
145149
template.WriteCode(path);
@@ -150,7 +154,7 @@ private void GenerateModelClasses(EntityContext entityContext)
150154
{
151155
foreach (var entity in entityContext.Entities)
152156
{
153-
if (entity.Models.Count <= 0)
157+
if (entity.Models.Count == 0)
154158
continue;
155159

156160
Options.Variables.Set(entity);
@@ -170,14 +174,14 @@ private void GenerateModelClasses(Entity entity)
170174
{
171175
Options.Variables.Set(model);
172176

173-
var directory = GetModelDirectory(model);
177+
var directory = GetModelDirectory(model) ?? "Data\\Models";
174178
var file = model.ModelClass + ".cs";
175179
var path = Path.Combine(directory, file);
176180

177-
_logger.LogInformation(File.Exists(path)
178-
? "Updating model class: {file}"
179-
: "Creating model class: {file}", file);
180-
181+
if (File.Exists(path))
182+
_logger.LogInformation("Updating model class: {file}", file);
183+
else
184+
_logger.LogInformation("Creating model class: {file}", file);
181185

182186
var template = new ModelClassTemplate(model, Options);
183187
template.WriteCode(path);
@@ -187,17 +191,21 @@ private void GenerateModelClasses(Entity entity)
187191

188192
}
189193

190-
private string GetModelDirectory(Model model)
194+
private string? GetModelDirectory(Model model)
191195
{
192196
if (model.ModelType == ModelType.Create)
197+
{
193198
return Options.Model.Create.Directory.HasValue()
194199
? Options.Model.Create.Directory
195200
: Options.Model.Shared.Directory;
201+
}
196202

197203
if (model.ModelType == ModelType.Update)
204+
{
198205
return Options.Model.Update.Directory.HasValue()
199206
? Options.Model.Update.Directory
200207
: Options.Model.Shared.Directory;
208+
}
201209

202210
return Options.Model.Read.Directory.HasValue()
203211
? Options.Model.Read.Directory
@@ -218,13 +226,14 @@ private void GenerateValidatorClasses(Entity entity)
218226
if (model.ModelType == ModelType.Read)
219227
continue;
220228

221-
var directory = Options.Model.Validator.Directory;
229+
var directory = Options.Model.Validator.Directory ?? "Data\\Validation";
222230
var file = model.ValidatorClass + ".cs";
223231
var path = Path.Combine(directory, file);
224232

225-
_logger.LogInformation(File.Exists(path)
226-
? "Updating validation class: {file}"
227-
: "Creating validation class: {file}", file);
233+
if (File.Exists(path))
234+
_logger.LogInformation("Updating validation class: {file}", file);
235+
else
236+
_logger.LogInformation("Creating validation class: {file}", file);
228237

229238
var template = new ValidatorClassTemplate(model, Options);
230239
template.WriteCode(path);
@@ -239,13 +248,14 @@ private void GenerateMapperClass(Entity entity)
239248
if (!Options.Model.Mapper.Generate)
240249
return;
241250

242-
var directory = Options.Model.Mapper.Directory;
251+
var directory = Options.Model.Mapper.Directory ?? "Data\\Mapper";
243252
var file = entity.MapperClass + ".cs";
244253
var path = Path.Combine(directory, file);
245254

246-
_logger.LogInformation(File.Exists(path)
247-
? "Updating object mapper class: {file}"
248-
: "Creating object mapper class: {file}", file);
255+
if (File.Exists(path))
256+
_logger.LogInformation("Updating mapper class: {file}", file);
257+
else
258+
_logger.LogInformation("Creating mapper class: {file}", file);
249259

250260
var template = new MapperClassTemplate(entity, Options);
251261
template.WriteCode(path);
@@ -367,18 +377,20 @@ private DatabaseModel GetDatabaseModel(IDatabaseModelFactory factory)
367377
var database = Options.Database;
368378

369379
var connectionString = ResolveConnectionString(database);
380+
if (string.IsNullOrEmpty(connectionString))
381+
throw new InvalidOperationException("Could not find connection string.");
370382

371383
var options = new DatabaseModelFactoryOptions(database.Tables, database.Schemas);
372384

373385
return factory.Create(connectionString, options);
374386
}
375387

376-
private string ResolveConnectionString(DatabaseOptions database)
388+
private static string? ResolveConnectionString(DatabaseOptions database)
377389
{
378390
if (database.ConnectionString.HasValue())
379391
return database.ConnectionString;
380392

381-
if (database.UserSecretsId.HasValue())
393+
if (database.UserSecretsId.HasValue() && database.ConnectionName.HasValue())
382394
{
383395
var secretsStore = new SecretsStore(database.UserSecretsId);
384396
if (secretsStore.ContainsKey(database.ConnectionName))
@@ -434,35 +446,35 @@ private string ResolveConnectionString(DatabaseOptions database)
434446
}
435447

436448

437-
private void ConfigureMySqlServices(IServiceCollection services)
449+
private static void ConfigureMySqlServices(IServiceCollection services)
438450
{
439451
var designTimeServices = new Pomelo.EntityFrameworkCore.MySql.Design.Internal.MySqlDesignTimeServices();
440452
designTimeServices.ConfigureDesignTimeServices(services);
441453
services.AddEntityFrameworkMySqlNetTopologySuite();
442454
}
443455

444-
private void ConfigurePostgresServices(IServiceCollection services)
456+
private static void ConfigurePostgresServices(IServiceCollection services)
445457
{
446458
var designTimeServices = new Npgsql.EntityFrameworkCore.PostgreSQL.Design.Internal.NpgsqlDesignTimeServices();
447459
designTimeServices.ConfigureDesignTimeServices(services);
448460
services.AddEntityFrameworkNpgsqlNetTopologySuite();
449461
}
450462

451-
private void ConfigureSqlServerServices(IServiceCollection services)
463+
private static void ConfigureSqlServerServices(IServiceCollection services)
452464
{
453465
var designTimeServices = new Microsoft.EntityFrameworkCore.SqlServer.Design.Internal.SqlServerDesignTimeServices();
454466
designTimeServices.ConfigureDesignTimeServices(services);
455467
services.AddEntityFrameworkSqlServerNetTopologySuite();
456468
}
457469

458-
private void ConfigureSqliteServices(IServiceCollection services)
470+
private static void ConfigureSqliteServices(IServiceCollection services)
459471
{
460472
var designTimeServices = new Microsoft.EntityFrameworkCore.Sqlite.Design.Internal.SqliteDesignTimeServices();
461473
designTimeServices.ConfigureDesignTimeServices(services);
462474
services.AddEntityFrameworkSqliteNetTopologySuite();
463475
}
464476

465-
private void ConfigureOracleServices(IServiceCollection services)
477+
private static void ConfigureOracleServices(IServiceCollection services)
466478
{
467479
var designTimeServices = new Oracle.EntityFrameworkCore.Design.Internal.OracleDesignTimeServices();
468480
designTimeServices.ConfigureDesignTimeServices(services);

src/EntityFrameworkCore.Generator.Core/ConfigurationSerializer.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ public ConfigurationSerializer(ILogger<ConfigurationSerializer> logger)
3737
/// <param name="directory">The directory where the file is located.</param>
3838
/// <param name="file">The name of the options file.</param>
3939
/// <returns>An instance of <see cref="Generator"/> if the file exists; otherwise <c>null</c>.</returns>
40-
public GeneratorModel Load(string directory = null, string file = OptionsFileName)
40+
public GeneratorModel? Load(string? directory = null, string file = OptionsFileName)
4141
{
4242
var path = GetPath(directory, file);
4343
if (!File.Exists(path))
4444
{
45-
_logger.LogWarning($"Option file not found: {file}");
45+
_logger.LogWarning("Option file not found: {file}", file);
4646
return null;
4747
}
4848

49-
_logger.LogInformation($"Loading options file: {file}");
49+
_logger.LogInformation("Loading options file: {file}", file);
5050
using var reader = File.OpenText(path);
5151

5252
return Load(reader);
@@ -59,7 +59,7 @@ public GeneratorModel Load(string directory = null, string file = OptionsFileNam
5959
/// <returns>
6060
/// An instance of <see cref="Generator" />.
6161
/// </returns>
62-
public GeneratorModel Load(TextReader reader)
62+
public GeneratorModel? Load(TextReader reader)
6363
{
6464
if (reader == null)
6565
return null;
@@ -79,7 +79,7 @@ public GeneratorModel Load(TextReader reader)
7979
/// <param name="directory">The directory where the file is located.</param>
8080
/// <param name="file">The name of the options file.</param>
8181
/// <returns>The full path of the options file.</returns>
82-
public string Save(GeneratorModel generatorOptions, string directory = null, string file = OptionsFileName)
82+
public string Save(GeneratorModel generatorOptions, string? directory = null, string file = OptionsFileName)
8383
{
8484
if (string.IsNullOrWhiteSpace(directory))
8585
directory = Environment.CurrentDirectory;
@@ -114,14 +114,14 @@ public string Save(GeneratorModel generatorOptions, string directory = null, str
114114
/// <param name="directory">The directory where the file is located.</param>
115115
/// <param name="file">The name of the options file.</param>
116116
/// <returns><c>true</c> if options file exits; otherwise <c>false</c>.</returns>
117-
public bool Exists(string directory = null, string file = OptionsFileName)
117+
public bool Exists(string? directory = null, string file = OptionsFileName)
118118
{
119119
var path = GetPath(directory, file);
120120
return File.Exists(path);
121121
}
122122

123123

124-
private static string GetPath(string directory, string file)
124+
private static string GetPath(string? directory, string? file)
125125
{
126126
if (string.IsNullOrWhiteSpace(directory))
127127
directory = Environment.CurrentDirectory;

src/EntityFrameworkCore.Generator.Core/EntityFrameworkCore.Generator.Core.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
<ItemGroup>
99
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="[4.8.0]" />
10-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.4" />
11-
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.4" />
12-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.4" />
13-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite" Version="9.0.4" />
14-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.4" />
15-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite" Version="9.0.4" />
16-
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.4" />
10+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.5" />
11+
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.5" />
12+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.5" />
13+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite" Version="9.0.5" />
14+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.5" />
15+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite" Version="9.0.5" />
16+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.5" />
1717
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
1818
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite" Version="9.0.4" />
1919
<PackageReference Include="Oracle.EntityFrameworkCore" Version="9.23.80" />

0 commit comments

Comments
 (0)