Skip to content

Commit fad1128

Browse files
committed
Update required for previous patch.
1 parent 83e4644 commit fad1128

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

EntityFramework.Reverse.POCO.Generator/Database NorthwindSqlCe40.tt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
UsePascalCase = true; // This will rename the generated C# tables & properties to use PascalCase. If false table & property names will be left alone.
2828
UseDataAnnotations = false; // If true, will add data annotations to the poco classes.
2929
UseDataAnnotationsSchema = false; // UseDataAnnotations must also be true. If true, will add data annotations schema to the poco classes.
30+
UsePropertyInitializers = false; // C# 6 feature
3031
IncludeComments = CommentsStyle.AtEndOfField; // Adds comments to the generated code
3132
IncludeExtendedPropertyComments = CommentsStyle.InSummaryBlock; // Adds extended properties as comments to the generated code
3233
IncludeViews = true;
@@ -358,6 +359,20 @@
358359
return "ContactPerson";
359360
*/
360361

362+
// FK_TableName_FromThisToParentRelationshipName_FromParentToThisChildsRelationshipName
363+
// (e.g. FK_CustomerAddress_Customer_Addresses will extract navigation properties "address.Customer" and "customer.Addresses")
364+
if (foreignKey.ConstraintName.StartsWith("FK_") && foreignKey.ConstraintName.Count(x => x == '_') == 3)
365+
{
366+
var parts = foreignKey.ConstraintName.Split('_');
367+
if (!string.IsNullOrWhiteSpace(parts[2]) && !string.IsNullOrWhiteSpace(parts[3]))
368+
{
369+
if (relationship == Relationship.OneToMany)
370+
fkName = parts[3];
371+
else if (relationship == Relationship.ManyToOne)
372+
fkName = parts[2];
373+
}
374+
}
375+
361376
return fkName;
362377
};
363378

EntityFramework.Reverse.POCO.Generator/Database.tt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
UsePascalCase = true; // This will rename the generated C# tables & properties to use PascalCase. If false table & property names will be left alone.
2828
UseDataAnnotations = false; // If true, will add data annotations to the poco classes.
2929
UseDataAnnotationsSchema = false; // UseDataAnnotations must also be true. If true, will add data annotations schema to the poco classes.
30+
UsePropertyInitializers = false; // C# 6 feature
3031
IncludeComments = CommentsStyle.AtEndOfField; // Adds comments to the generated code
3132
IncludeExtendedPropertyComments = CommentsStyle.InSummaryBlock; // Adds extended properties as comments to the generated code
3233
IncludeViews = true;
@@ -412,6 +413,20 @@
412413
return "ContactPerson";
413414
*/
414415

416+
// FK_TableName_FromThisToParentRelationshipName_FromParentToThisChildsRelationshipName
417+
// (e.g. FK_CustomerAddress_Customer_Addresses will extract navigation properties "address.Customer" and "customer.Addresses")
418+
if (foreignKey.ConstraintName.StartsWith("FK_") && foreignKey.ConstraintName.Count(x => x == '_') == 3)
419+
{
420+
var parts = foreignKey.ConstraintName.Split('_');
421+
if (!string.IsNullOrWhiteSpace(parts[2]) && !string.IsNullOrWhiteSpace(parts[3]))
422+
{
423+
if (relationship == Relationship.OneToMany)
424+
fkName = parts[3];
425+
else if (relationship == Relationship.ManyToOne)
426+
fkName = parts[2];
427+
}
428+
}
429+
415430
return fkName;
416431
};
417432

EntityFramework.Reverse.POCO.Generator/EF.Reverse.POCO.Core.ttinclude

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
bool MakeDbContextInterfacePartial = false;
5656
bool GenerateSeparateFiles = false;
5757
bool UseMappingTables = true;
58-
static bool UsePropertyInitializers = false;
58+
bool UsePropertyInitializers = false;
5959
bool IsSqlCe = false;
6060
string FileExtension = ".cs";
6161
bool UsePascalCase = true;
@@ -3275,7 +3275,7 @@ SELECT SERVERPROPERTY('Edition') AS Edition,
32753275
{
32763276
case Relationship.OneToOne:
32773277
ReverseNavigationProperty.Add(
3278-
new PropertyAndComments()
3278+
new PropertyAndComments()
32793279
{
32803280
Definition = string.Format("public virtual {0} {1} {{ get; set; }}{2}", fkTable.NameHumanCaseWithSuffix, propName, includeComments != CommentsStyle.None ? " // " + constraint : string.Empty),
32813281
Comments = string.Format("Parent (One-to-One) {0} pointed by [{1}].{2} ({3})", this.NameHumanCaseWithSuffix, fkTable.Name, fkNames, fks.First().ConstraintName)
@@ -3285,7 +3285,7 @@ SELECT SERVERPROPERTY('Edition') AS Edition,
32853285

32863286
case Relationship.OneToMany:
32873287
ReverseNavigationProperty.Add(
3288-
new PropertyAndComments()
3288+
new PropertyAndComments()
32893289
{
32903290
Definition = string.Format("public virtual {0} {1} {{ get; set; }}{2}", fkTable.NameHumanCaseWithSuffix, propName, includeComments != CommentsStyle.None ? " // " + constraint : string.Empty),
32913291
Comments = string.Format("Parent {0} pointed by [{1}].{2} ({3})", this.NameHumanCaseWithSuffix, fkTable.Name, fkNames, fks.First().ConstraintName)
@@ -3296,7 +3296,7 @@ SELECT SERVERPROPERTY('Edition') AS Edition,
32963296
case Relationship.ManyToOne:
32973297
var initialization1 = string.Format(" = new {0}<{1}>();", collectionType, fkTable.NameHumanCaseWithSuffix);
32983298
ReverseNavigationProperty.Add(
3299-
new PropertyAndComments()
3299+
new PropertyAndComments()
33003300
{
33013301
Definition = string.Format("public virtual System.Collections.Generic.ICollection<{0}> {1} {{ get; set; }}{2}{3}", fkTable.NameHumanCaseWithSuffix, propName, initialization1, includeComments != CommentsStyle.None ? " // " + constraint : string.Empty),
33023302
Comments = string.Format("Child {0} where [{1}].{2} point to this entity ({3})", Inflector.MakePlural(fkTable.NameHumanCase), fkTable.Name, fkNames, fks.First().ConstraintName)
@@ -3308,7 +3308,7 @@ SELECT SERVERPROPERTY('Edition') AS Edition,
33083308
case Relationship.ManyToMany:
33093309
var initialization2 = string.Format(" = new {0}<{1}>();", collectionType, fkTable.NameHumanCaseWithSuffix);
33103310
ReverseNavigationProperty.Add(
3311-
new PropertyAndComments()
3311+
new PropertyAndComments()
33123312
{
33133313
Definition = string.Format("public virtual System.Collections.Generic.ICollection<{0}> {1} {{ get; set; }}{2}{3}", fkTable.NameHumanCaseWithSuffix, propName, initialization2, includeComments != CommentsStyle.None ? " // Many to many mapping" : string.Empty),
33143314
Comments = string.Format("Child {0} (Many-to-Many) mapped by table [{1}]", Inflector.MakePlural(fkTable.NameHumanCase), mappingTable.Name)

0 commit comments

Comments
 (0)