|
369 | 369 | // column.OverrideModifier = true; |
370 | 370 | // This will create: public override long id { get; set; } |
371 | 371 |
|
| 372 | + // Make property partial, see https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator/wiki/Partial-properties |
| 373 | + //if (table.NameHumanCase.Equals("SomeTable", StringComparison.InvariantCultureIgnoreCase) && column.NameHumanCase.Equals("SomeColumn", StringComparison.InvariantCultureIgnoreCase)) |
| 374 | + // column.IsPartial = true; |
| 375 | + |
| 376 | + if (UseDataAnnotations) |
| 377 | + { |
| 378 | + if (column.IsPrimaryKey) |
| 379 | + column.Attributes.Add(string.Format("[Key, Column(Order = {0})]", column.Ordinal)); |
| 380 | + |
| 381 | + if (column.IsMaxLength) |
| 382 | + column.Attributes.Add("[MaxLength]"); |
| 383 | + |
| 384 | + if (column.IsRowVersion) |
| 385 | + column.Attributes.Add("[Timestamp, ConcurrencyCheck]"); |
| 386 | + |
| 387 | + if (!column.IsMaxLength && column.MaxLength > 0) |
| 388 | + { |
| 389 | + var doNotSpecifySize = (DatabaseType == DatabaseType.SqlCe && column.MaxLength > 4000); |
| 390 | + column.Attributes.Add(doNotSpecifySize ? "[MaxLength]" : string.Format("[MaxLength({0})]", column.MaxLength)); |
| 391 | + if (column.PropertyType.Equals("string", StringComparison.InvariantCultureIgnoreCase)) |
| 392 | + column.Attributes.Add(string.Format("[StringLength({0})]", column.MaxLength)); |
| 393 | + } |
| 394 | + |
| 395 | + if (!column.IsNullable && !column.IsComputed) |
| 396 | + { |
| 397 | + if (column.PropertyType.Equals("string", StringComparison.InvariantCultureIgnoreCase) && column.AllowEmptyStrings) |
| 398 | + column.Attributes.Add("[Required(AllowEmptyStrings = true)]"); |
| 399 | + else |
| 400 | + column.Attributes.Add("[Required]"); |
| 401 | + } |
| 402 | + |
| 403 | + column.Attributes.Add(string.Format("[Display(Name = \"{0}\")]", column.DisplayName)); |
| 404 | + } |
| 405 | + |
372 | 406 | // Perform Enum property type replacement |
373 | 407 | var enumDefinition = enumDefinitions?.FirstOrDefault(e => |
374 | 408 | (e.Schema.Equals(table.Schema.DbName, StringComparison.InvariantCultureIgnoreCase)) && |
|
1222 | 1256 | public bool IsMaxLength; |
1223 | 1257 | public bool IsForeignKey; |
1224 | 1258 | public bool IsSpatial; |
| 1259 | + public bool IsPartial; |
1225 | 1260 |
|
1226 | 1261 | public string Config; |
1227 | 1262 | public List<string> ConfigFk = new List<string>(); |
|
3935 | 3970 | HasNoPrimaryKey = !table.HasPrimaryKey, |
3936 | 3971 | Name = table.DbName, |
3937 | 3972 | NameHumanCaseWithSuffix = table.NameHumanCaseWithSuffix(), |
3938 | | - ClassModifier = Settings.EntityClassesModifiers, |
| 3973 | + ClassModifier = columnsQuery |
| 3974 | + .Where(x => !x.Hidden && !x.ExistsInBaseClass) |
| 3975 | + .Any(x => x.IsPartial) ? "public partial" : Settings.EntityClassesModifiers, |
3939 | 3976 | ClassComment = table.WriteComments(), |
3940 | 3977 | ExtendedComments = table.WriteExtendedComments(), |
3941 | 3978 | ClassAttributes = table.WriteClassAttributes(), |
|
3956 | 3993 | NameHumanCase = col.NameHumanCase, |
3957 | 3994 | PrivateSetterForComputedColumns = Settings.UsePrivateSetterForComputedColumns && col.IsComputed ? "private " : string.Empty, |
3958 | 3995 | PropertyInitialisers = Settings.UsePropertyInitialisers ? (string.IsNullOrWhiteSpace(col.Default) ? string.Empty : string.Format(" = {0};", col.Default)) : string.Empty, |
3959 | | - InlineComments = col.InlineComments |
| 3996 | + InlineComments = col.InlineComments, |
| 3997 | + IsPartial = col.IsPartial |
3960 | 3998 | }) |
3961 | 3999 | .ToList(), |
3962 | 4000 | HasReverseNavigation = table.ReverseNavigationProperty.Count > 0, |
@@ -17647,6 +17685,7 @@ SELECT SERVERPROPERTY('Edition') AS Edition, |
17647 | 17685 | public string PrivateSetterForComputedColumns { get; set; } |
17648 | 17686 | public string PropertyInitialisers { get; set; } |
17649 | 17687 | public string InlineComments { get; set; } |
| 17688 | + public bool IsPartial { get; set; } |
17650 | 17689 | } |
17651 | 17690 |
|
17652 | 17691 | public class PocoReverseNavigationPropertyModel |
@@ -18847,7 +18886,7 @@ using {{this}};{{#newline}} |
18847 | 18886 | {{#each Attributes}} |
18848 | 18887 | {{this}}{{#newline}} |
18849 | 18888 | {{/each}} |
18850 | | - public {{#if OverrideModifier}}override {{/if}}{{WrapIfNullable}} {{NameHumanCase}} { get; {{PrivateSetterForComputedColumns}}set; }{{PropertyInitialisers}}{{InlineComments}}{{#newline}} |
| 18889 | + public {{#if OverrideModifier}}override {{/if}}{{#if IsPartial}}partial {{/if}}{{WrapIfNullable}} {{NameHumanCase}} { get; {{PrivateSetterForComputedColumns}}set; }{{PropertyInitialisers}}{{InlineComments}}{{#newline}} |
18851 | 18890 | {{#if IncludeFieldNameConstants}} public const string {{NameHumanCase}}Field = ""{{NameHumanCase}}"";{{#newline}}{{/if}} |
18852 | 18891 | {{/each}} |
18853 | 18892 |
|
@@ -20522,7 +20561,7 @@ public class FakeDbContextTransaction : IDbContextTransaction{{#newline}} |
20522 | 20561 | {{#each Attributes}} |
20523 | 20562 | {{this}}{{#newline}} |
20524 | 20563 | {{/each}} |
20525 | | - public {{#if OverrideModifier}}override {{/if}}{{WrapIfNullable}} {{NameHumanCase}} { get; {{PrivateSetterForComputedColumns}}set; }{{PropertyInitialisers}}{{InlineComments}}{{#newline}} |
| 20564 | + public {{#if OverrideModifier}}override {{/if}}{{#if IsPartial}}partial {{/if}}{{WrapIfNullable}} {{NameHumanCase}} { get; {{PrivateSetterForComputedColumns}}set; }{{PropertyInitialisers}}{{InlineComments}}{{#newline}} |
20526 | 20565 | {{#if IncludeFieldNameConstants}} public const string {{NameHumanCase}}Field = ""{{NameHumanCase}}"";{{#newline}}{{/if}} |
20527 | 20566 | {{/each}} |
20528 | 20567 |
|
|
0 commit comments