Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/Pingmint.CodeGen.Sql/CodeFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,17 @@ public String GenerateCode()

using var tableClass = code.PartialClass("public sealed", dataTableClassName, "DataTable");
code.Line("public {0}() : this(new List<{1}>()) {{ }}", dataTableClassName, rowClassName);
code.Line("public {0}(List<{1}> rows) : base()", dataTableClassName, rowClassName);
code.Line("public {0}(List<{1}>? rows) : base()", dataTableClassName, rowClassName);
using (code.CreateBraceScope())
{
code.Line("ArgumentNullException.ThrowIfNull(rows);");
code.Line();
foreach (var col in record.Properties)
{
var allowDbNull = col.ColumnIsNullable ? "true" : "false";
var maxLength = (col.MaxLength is short s && col.FieldType?.ToLowerInvariant() == "string") ? $", MaxLength = {s}" : String.Empty; // the default is already "-1", so we do not have to emit this in code.
var propertyTypeName = col.FieldTypeWithoutNullable;
code.Line("base.Columns.Add(new DataColumn() {{ ColumnName = \"{0}\", DataType = typeof({1}), AllowDBNull = {2}{3} }});", col.ColumnName, propertyTypeName, allowDbNull, maxLength);
}
using (code.ForEach("var row in rows"))
using (code.ForEach("var row in rows ?? []"))
{
var parameterBuilder = String.Empty;
foreach (var col in record.Properties)
Expand Down
2 changes: 1 addition & 1 deletion src/Pingmint.CodeGen.Sql/Pingmint.CodeGen.Sql.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>0.47</Version>
<Version>0.48</Version>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>latest</LangVersion>
Expand Down
Loading