Skip to content

Commit 485487c

Browse files
authored
Merge branch 'master' into Feature/navprop_decl
2 parents 0da693a + 0936266 commit 485487c

File tree

6 files changed

+182
-31
lines changed

6 files changed

+182
-31
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: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//ProviderName = "System.Data.SqlServerCe.4.0";
1414

1515
Namespace = "EntityFramework_Reverse_POCO_Generator.SqlCe4"; // Override the default namespace here
16-
DbContextName = "MyDbContextSqlCE4";
16+
DbContextName = "MyDbContextSqlCE4"; // Note: If generating separate files, please give the db context a different name from this tt filename.
1717
//DbContextInterfaceName = "IMyDbContextSqlCE4"; // Defaults to "I" + DbContextName or set string empty to not implement any interface.
1818
DbContextInterfaceBaseClasses = "System.IDisposable"; // Specify what the base classes are for your database context interface
1919
DbContextBaseClass = "System.Data.Entity.DbContext"; // Specify what the base class is for your DbContext. For ASP.NET Identity use "IdentityDbContext<ApplicationUser>"
@@ -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
@@ -269,6 +270,18 @@
269270
{
270271
//if (t.ClassName == "User")
271272
// return ": IdentityUser<int, CustomUserLogin, CustomUserRole, CustomUserClaim>";
273+
274+
// Or use the maker class to dynamically build more complex definitions
275+
/* Example:
276+
var r = new BaseClassMaker("POCO.Sample.Data.MetaModelObject");
277+
r.AddInterface("POCO.Sample.Data.IObjectWithTableName");
278+
r.AddInterface("POCO.Sample.Data.IObjectWithId",
279+
t.Columns.Any(x => x.IsPrimaryKey && !x.IsNullable && x.NameHumanCase.Equals("Id", StringComparison.InvariantCultureIgnoreCase) && x.PropertyType == "long"));
280+
r.AddInterface("POCO.Sample.Data.IObjectWithUserId",
281+
t.Columns.Any(x => !x.IsPrimaryKey && !x.IsNullable && x.NameHumanCase.Equals("UserId", StringComparison.InvariantCultureIgnoreCase) && x.PropertyType == "long"));
282+
return r.ToString();
283+
*/
284+
272285
return "";
273286
};
274287

@@ -404,6 +417,20 @@
404417
return fkName;
405418
};
406419

420+
ForeignKeyAnnotationsProcessing = (Table fkTable, Table pkTable, string propName) =>
421+
{
422+
/* Example:
423+
// Each navigation property that is a reference to User are left intact
424+
if (pkTable.NameHumanCase.Equals("User") && propName.Equals("User"))
425+
return null;
426+
427+
// all the others are marked with this attribute
428+
return new[] { "System.Runtime.Serialization.IgnoreDataMember" };
429+
*/
430+
431+
return null;
432+
};
433+
407434
// Return true to include this table in the db context
408435
ConfigurationFilter = (Table t) =>
409436
{

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: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//ProviderName = "System.Data.SqlClient";
1414

1515
// Namespace = ""; // Override the default namespace here
16-
DbContextName = "MyDbContext";
16+
DbContextName = "MyDbContext"; // Note: If generating separate files, please give the db context a different name from this tt filename.
1717
//DbContextInterfaceName = "IMyDbContext"; // Defaults to "I" + DbContextName or set string empty to not implement any interface.
1818
DbContextInterfaceBaseClasses = "System.IDisposable"; // Specify what the base classes are for your database context interface
1919
DbContextBaseClass = "System.Data.Entity.DbContext"; // Specify what the base class is for your DbContext. For ASP.NET Identity use "IdentityDbContext<ApplicationUser>"
@@ -53,6 +53,7 @@
5353
// If you need to serialize your entities with the JsonSerializer from Newtonsoft, this would serialize
5454
// all properties including the Reverse Navigation and Foreign Keys. The simplest way to exclude them is
5555
// to use the data annotation [JsonIgnore] on reverse navigation and foreign keys.
56+
// For more control, take a look at ForeignKeyAnnotationsProcessing() further down
5657
AdditionalReverseNavigationsDataAnnotations = new string[] // Data Annotations for all ReverseNavigationProperty.
5758
{
5859
// "JsonIgnore" // Also add "Newtonsoft.Json" to the AdditionalNamespaces array above
@@ -324,6 +325,18 @@
324325
{
325326
//if (t.ClassName == "User")
326327
// return ": IdentityUser<int, CustomUserLogin, CustomUserRole, CustomUserClaim>";
328+
329+
// Or use the maker class to dynamically build more complex definitions
330+
/* Example:
331+
var r = new BaseClassMaker("POCO.Sample.Data.MetaModelObject");
332+
r.AddInterface("POCO.Sample.Data.IObjectWithTableName");
333+
r.AddInterface("POCO.Sample.Data.IObjectWithId",
334+
t.Columns.Any(x => x.IsPrimaryKey && !x.IsNullable && x.NameHumanCase.Equals("Id", StringComparison.InvariantCultureIgnoreCase) && x.PropertyType == "long"));
335+
r.AddInterface("POCO.Sample.Data.IObjectWithUserId",
336+
t.Columns.Any(x => !x.IsPrimaryKey && !x.IsNullable && x.NameHumanCase.Equals("UserId", StringComparison.InvariantCultureIgnoreCase) && x.PropertyType == "long"));
337+
return r.ToString();
338+
*/
339+
327340
return "";
328341
};
329342

@@ -459,6 +472,20 @@
459472
return fkName;
460473
};
461474

475+
ForeignKeyAnnotationsProcessing = (Table fkTable, Table pkTable, string propName) =>
476+
{
477+
/* Example:
478+
// Each navigation property that is a reference to User are left intact
479+
if (pkTable.NameHumanCase.Equals("User") && propName.Equals("User"))
480+
return null;
481+
482+
// all the others are marked with this attribute
483+
return new[] { "System.Runtime.Serialization.IgnoreDataMember" };
484+
*/
485+
486+
return null;
487+
};
488+
462489
// Return true to include this table in the db context
463490
ConfigurationFilter = (Table t) =>
464491
{

0 commit comments

Comments
 (0)