Skip to content

Commit b6af0d3

Browse files
committed
#303 A few tweaks and sync SqlCE tt file.
1 parent 8d65369 commit b6af0d3

File tree

6 files changed

+36
-14
lines changed

6 files changed

+36
-14
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,10 +595,12 @@ public class Order
595595
/// Parent Customer pointed by [Orders].([CustomerId]) (Orders_FK00)
596596
/// </summary>
597597
public virtual Customer Customer { get; set; } // Orders_FK00
598+
598599
/// <summary>
599600
/// Parent Employee pointed by [Orders].([EmployeeId]) (Orders_FK02)
600601
/// </summary>
601602
public virtual Employee Employee { get; set; } // Orders_FK02
603+
602604
/// <summary>
603605
/// Parent Shipper pointed by [Orders].([ShipVia]) (Orders_FK01)
604606
/// </summary>
@@ -626,6 +628,7 @@ public class OrderDetail
626628
/// Parent Order pointed by [Order Details].([OrderId]) (Order Details_FK01)
627629
/// </summary>
628630
public virtual Order Order { get; set; } // Order Details_FK01
631+
629632
/// <summary>
630633
/// Parent Product pointed by [Order Details].([ProductId]) (Order Details_FK00)
631634
/// </summary>
@@ -661,6 +664,7 @@ public class Product
661664
/// Parent Category pointed by [Products].([CategoryId]) (Products_FK01)
662665
/// </summary>
663666
public virtual Category Category { get; set; } // Products_FK01
667+
664668
/// <summary>
665669
/// Parent Supplier pointed by [Products].([SupplierId]) (Products_FK00)
666670
/// </summary>

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
// If you need to serialize your entities with the JsonSerializer from Newtonsoft, this would serialize
4949
// all properties including the Reverse Navigation and Foreign Keys. The simplest way to exclude them is
5050
// to use the data annotation [JsonIgnore] on reverse navigation and foreign keys.
51+
// For more control, take a look at ForeignKeyAnnotationsProcessing() further down
5152
AdditionalReverseNavigationsDataAnnotations = new string[] // Data Annotations for all ReverseNavigationProperty.
5253
{
5354
// "JsonIgnore" // Also add "Newtonsoft.Json" to the AdditionalNamespaces array above
@@ -404,6 +405,20 @@
404405
return fkName;
405406
};
406407

408+
ForeignKeyAnnotationsProcessing = (Table fkTable, Table pkTable, string propName) =>
409+
{
410+
/* Example:
411+
// Each navigation property that is a reference to User are left intact
412+
if (pkTable.NameHumanCase.Equals("User") && propName.Equals("User"))
413+
return null;
414+
415+
// all the others are marked with this attribute
416+
return new[] { "System.Runtime.Serialization.IgnoreDataMember" };
417+
*/
418+
419+
return null;
420+
};
421+
407422
// Return true to include this table in the db context
408423
ConfigurationFilter = (Table t) =>
409424
{

EntityFramework.Reverse.POCO.Generator/Database.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,10 +1227,12 @@ public class Order
12271227
/// Parent Customer pointed by [Orders].([CustomerId]) (FK_Orders_Customers)
12281228
/// </summary>
12291229
public virtual Customer Customer { get; set; } // FK_Orders_Customers
1230+
12301231
/// <summary>
12311232
/// Parent Employee pointed by [Orders].([EmployeeId]) (FK_Orders_Employees)
12321233
/// </summary>
12331234
public virtual Employee Employee { get; set; } // FK_Orders_Employees
1235+
12341236
/// <summary>
12351237
/// Parent Shipper pointed by [Orders].([ShipVia]) (FK_Orders_Shippers)
12361238
/// </summary>
@@ -1259,6 +1261,7 @@ public class OrderDetail
12591261
/// Parent Order pointed by [Order Details].([OrderId]) (FK_Order_Details_Orders)
12601262
/// </summary>
12611263
public virtual Order Order { get; set; } // FK_Order_Details_Orders
1264+
12621265
/// <summary>
12631266
/// Parent Product pointed by [Order Details].([ProductId]) (FK_Order_Details_Products)
12641267
/// </summary>
@@ -1347,6 +1350,7 @@ public class Product
13471350
/// Parent Category pointed by [Products].([CategoryId]) (FK_Products_Categories)
13481351
/// </summary>
13491352
public virtual Category Category { get; set; } // FK_Products_Categories
1353+
13501354
/// <summary>
13511355
/// Parent Supplier pointed by [Products].([SupplierId]) (FK_Products_Suppliers)
13521356
/// </summary>

EntityFramework.Reverse.POCO.Generator/Database.tt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
// If you need to serialize your entities with the JsonSerializer from Newtonsoft, this would serialize
5353
// all properties including the Reverse Navigation and Foreign Keys. The simplest way to exclude them is
5454
// to use the data annotation [JsonIgnore] on reverse navigation and foreign keys.
55+
// For more control, take a look at ForeignKeyAnnotationsProcessing() further down
5556
AdditionalReverseNavigationsDataAnnotations = new string[] // Data Annotations for all ReverseNavigationProperty.
5657
{
5758
// "JsonIgnore" // Also add "Newtonsoft.Json" to the AdditionalNamespaces array above
@@ -458,20 +459,19 @@
458459
return fkName;
459460
};
460461

461-
/*
462462
ForeignKeyAnnotationsProcessing = (Table fkTable, Table pkTable, string propName) =>
463463
{
464-
// each navigation property that is a reference to User are left intact
465-
if (pkTable.NameHumanCase.Equals("User"))
466-
{
467-
if (propName.Equals("User"))
468-
return null;
469-
}
464+
/* Example:
465+
// Each navigation property that is a reference to User are left intact
466+
if (pkTable.NameHumanCase.Equals("User") && propName.Equals("User"))
467+
return null;
470468

471469
// all the others are marked with this attribute
472470
return new[] { "System.Runtime.Serialization.IgnoreDataMember" };
471+
*/
472+
473+
return null;
473474
};
474-
*/
475475

476476
// Return true to include this table in the db context
477477
ConfigurationFilter = (Table t) =>

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2672,7 +2672,7 @@ SELECT SERVERPROPERTY('Edition') AS Edition,
26722672
}
26732673

26742674
var fkd = new PropertyAndComments();
2675-
fkd.AdditionalDataAnnotations = foreignKeyAnnotationsProcessing != null ? foreignKeyAnnotationsProcessing(fkTable, pkTable, pkPropName) : null;
2675+
fkd.AdditionalDataAnnotations = foreignKeyAnnotationsProcessing(fkTable, pkTable, pkPropName);
26762676
fkd.Definition = string.Format("{0}public {1}{2} {3} {4}{5}", dataAnnotation, Table.GetLazyLoadingMarker(), pkTableHumanCaseWithSuffix, pkPropName, "{ get; set; }", includeComments != CommentsStyle.None ? " // " + foreignKey.ConstraintName : string.Empty);
26772677
fkd.Comments = string.Format("Parent {0} pointed by [{1}].({2}) ({3})", pkTableHumanCase, fkTable.Name, string.Join(", ", fkCols.Select(x => "[" + x.col.NameHumanCase + "]").Distinct().ToArray()), foreignKey.ConstraintName);
26782678
fkCol.col.EntityFk.Add(fkd);
@@ -3342,7 +3342,7 @@ SELECT SERVERPROPERTY('Edition') AS Edition,
33423342
ReverseNavigationProperty.Add(
33433343
new PropertyAndComments()
33443344
{
3345-
AdditionalDataAnnotations = foreignKeyAnnotationsProcessing != null ? foreignKeyAnnotationsProcessing(fkTable, this, propName) : null,
3345+
AdditionalDataAnnotations = foreignKeyAnnotationsProcessing(fkTable, this, propName),
33463346
Definition = string.Format("public {0}{1} {2} {{ get; set; }}{3}", GetLazyLoadingMarker(), fkTable.NameHumanCaseWithSuffix, propName, includeComments != CommentsStyle.None ? " // " + constraint : string.Empty),
33473347
Comments = string.Format("Parent (One-to-One) {0} pointed by [{1}].{2} ({3})", this.NameHumanCaseWithSuffix, fkTable.Name, fkNames, fks.First().ConstraintName)
33483348
}
@@ -3353,7 +3353,7 @@ SELECT SERVERPROPERTY('Edition') AS Edition,
33533353
ReverseNavigationProperty.Add(
33543354
new PropertyAndComments()
33553355
{
3356-
AdditionalDataAnnotations = foreignKeyAnnotationsProcessing != null ? foreignKeyAnnotationsProcessing(fkTable, this, propName) : null,
3356+
AdditionalDataAnnotations = foreignKeyAnnotationsProcessing(fkTable, this, propName),
33573357
Definition = string.Format("public {0}{1} {2} {{ get; set; }}{3}", GetLazyLoadingMarker(), fkTable.NameHumanCaseWithSuffix, propName, includeComments != CommentsStyle.None ? " // " + constraint : string.Empty),
33583358
Comments = string.Format("Parent {0} pointed by [{1}].{2} ({3})", NameHumanCaseWithSuffix, fkTable.Name, fkNames, fks.First().ConstraintName)
33593359
}
@@ -3367,7 +3367,7 @@ SELECT SERVERPROPERTY('Edition') AS Edition,
33673367
ReverseNavigationProperty.Add(
33683368
new PropertyAndComments()
33693369
{
3370-
AdditionalDataAnnotations = foreignKeyAnnotationsProcessing != null ? foreignKeyAnnotationsProcessing(fkTable, this, propName) : null,
3370+
AdditionalDataAnnotations = foreignKeyAnnotationsProcessing(fkTable, this, propName),
33713371
Definition = string.Format("public {0}System.Collections.Generic.ICollection<{1}> {2} {{ get; set; }}{3}{4}", GetLazyLoadingMarker(), fkTable.NameHumanCaseWithSuffix, propName, initialization1, includeComments != CommentsStyle.None ? " // " + constraint : string.Empty),
33723372
Comments = string.Format("Child {0} where [{1}].{2} point to this entity ({3})", Inflector.MakePlural(fkTable.NameHumanCase), fkTable.Name, fkNames, fks.First().ConstraintName)
33733373
}
@@ -3382,7 +3382,7 @@ SELECT SERVERPROPERTY('Edition') AS Edition,
33823382
ReverseNavigationProperty.Add(
33833383
new PropertyAndComments()
33843384
{
3385-
AdditionalDataAnnotations = foreignKeyAnnotationsProcessing != null ? foreignKeyAnnotationsProcessing(fkTable, this, propName) : null,
3385+
AdditionalDataAnnotations = foreignKeyAnnotationsProcessing(fkTable, this, propName),
33863386
Definition = string.Format("public {0}System.Collections.Generic.ICollection<{1}> {2} {{ get; set; }}{3}{4}", GetLazyLoadingMarker(), fkTable.NameHumanCaseWithSuffix, propName, initialization2, includeComments != CommentsStyle.None ? " // Many to many mapping" : string.Empty),
33873387
Comments = string.Format("Child {0} (Many-to-Many) mapped by table [{1}]", Inflector.MakePlural(fkTable.NameHumanCase), mappingTable == null ? string.Empty : mappingTable.Name)
33883388
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,6 @@ if(tbl.ReverseNavigationProperty.Count() > 0)
988988
<#
989989
foreach(var s in tbl.ReverseNavigationProperty.OrderBy(x => x.Definition))
990990
{ #>
991-
992991
<# if(IncludeComments != CommentsStyle.None){#> /// <summary>
993992
/// <#=s.Comments ?? "" #>
994993
/// </summary>

0 commit comments

Comments
 (0)