Skip to content

Commit 8c29de4

Browse files
committed
#215 Fix for UsePropertyInitializers=false as prop initialisers were still being used.
1 parent 54a3cdb commit 8c29de4

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ public class Category
492492
/// <summary>
493493
/// Child Products where [Products].[Category ID] point to this entity (Products_FK01)
494494
/// </summary>
495-
public virtual System.Collections.Generic.ICollection<Product> Products { get; set; } = new System.Collections.Generic.List<Product>(); // Products.Products_FK01
495+
public virtual System.Collections.Generic.ICollection<Product> Products { get; set; } // Products.Products_FK01
496496

497497
public Category()
498498
{
@@ -521,7 +521,7 @@ public class Customer
521521
/// <summary>
522522
/// Child Orders where [Orders].[Customer ID] point to this entity (Orders_FK00)
523523
/// </summary>
524-
public virtual System.Collections.Generic.ICollection<Order> Orders { get; set; } = new System.Collections.Generic.List<Order>(); // Orders.Orders_FK00
524+
public virtual System.Collections.Generic.ICollection<Order> Orders { get; set; } // Orders.Orders_FK00
525525

526526
public Customer()
527527
{
@@ -555,7 +555,7 @@ public class Employee
555555
/// <summary>
556556
/// Child Orders where [Orders].[Employee ID] point to this entity (Orders_FK02)
557557
/// </summary>
558-
public virtual System.Collections.Generic.ICollection<Order> Orders { get; set; } = new System.Collections.Generic.List<Order>(); // Orders.Orders_FK02
558+
public virtual System.Collections.Generic.ICollection<Order> Orders { get; set; } // Orders.Orders_FK02
559559

560560
public Employee()
561561
{
@@ -587,7 +587,7 @@ public class Order
587587
/// <summary>
588588
/// Child OrderDetails where [Order Details].[Order ID] point to this entity (Order Details_FK01)
589589
/// </summary>
590-
public virtual System.Collections.Generic.ICollection<OrderDetail> OrderDetails { get; set; } = new System.Collections.Generic.List<OrderDetail>(); // Order Details.Order Details_FK01
590+
public virtual System.Collections.Generic.ICollection<OrderDetail> OrderDetails { get; set; } // Order Details.Order Details_FK01
591591

592592
// Foreign keys
593593

@@ -653,7 +653,7 @@ public class Product
653653
/// <summary>
654654
/// Child OrderDetails where [Order Details].[Product ID] point to this entity (Order Details_FK00)
655655
/// </summary>
656-
public virtual System.Collections.Generic.ICollection<OrderDetail> OrderDetails { get; set; } = new System.Collections.Generic.List<OrderDetail>(); // Order Details.Order Details_FK00
656+
public virtual System.Collections.Generic.ICollection<OrderDetail> OrderDetails { get; set; } // Order Details.Order Details_FK00
657657

658658
// Foreign keys
659659

@@ -684,7 +684,7 @@ public class Shipper
684684
/// <summary>
685685
/// Child Orders where [Orders].[Ship Via] point to this entity (Orders_FK01)
686686
/// </summary>
687-
public virtual System.Collections.Generic.ICollection<Order> Orders { get; set; } = new System.Collections.Generic.List<Order>(); // Orders.Orders_FK01
687+
public virtual System.Collections.Generic.ICollection<Order> Orders { get; set; } // Orders.Orders_FK01
688688

689689
public Shipper()
690690
{
@@ -713,7 +713,7 @@ public class Supplier
713713
/// <summary>
714714
/// Child Products where [Products].[Supplier ID] point to this entity (Products_FK00)
715715
/// </summary>
716-
public virtual System.Collections.Generic.ICollection<Product> Products { get; set; } = new System.Collections.Generic.List<Product>(); // Products.Products_FK00
716+
public virtual System.Collections.Generic.ICollection<Product> Products { get; set; } // Products.Products_FK00
717717

718718
public Supplier()
719719
{

EntityFramework.Reverse.POCO.Generator/Database.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ public class Category
10221022
/// <summary>
10231023
/// Child Products where [Products].[CategoryID] point to this entity (FK_Products_Categories)
10241024
/// </summary>
1025-
public virtual System.Collections.Generic.ICollection<Product> Products { get; set; } = new System.Collections.Generic.List<Product>(); // Products.FK_Products_Categories
1025+
public virtual System.Collections.Generic.ICollection<Product> Products { get; set; } // Products.FK_Products_Categories
10261026

10271027
public Category()
10281028
{
@@ -1067,11 +1067,11 @@ public class Customer
10671067
/// <summary>
10681068
/// Child CustomerDemographics (Many-to-Many) mapped by table [CustomerCustomerDemo]
10691069
/// </summary>
1070-
public virtual System.Collections.Generic.ICollection<CustomerDemographic> CustomerDemographics { get; set; } = new System.Collections.Generic.List<CustomerDemographic>(); // Many to many mapping
1070+
public virtual System.Collections.Generic.ICollection<CustomerDemographic> CustomerDemographics { get; set; } // Many to many mapping
10711071
/// <summary>
10721072
/// Child Orders where [Orders].[CustomerID] point to this entity (FK_Orders_Customers)
10731073
/// </summary>
1074-
public virtual System.Collections.Generic.ICollection<Order> Orders { get; set; } = new System.Collections.Generic.List<Order>(); // Orders.FK_Orders_Customers
1074+
public virtual System.Collections.Generic.ICollection<Order> Orders { get; set; } // Orders.FK_Orders_Customers
10751075

10761076
public Customer()
10771077
{
@@ -1102,7 +1102,7 @@ public class CustomerDemographic
11021102
/// <summary>
11031103
/// Child Customers (Many-to-Many) mapped by table [CustomerCustomerDemo]
11041104
/// </summary>
1105-
public virtual System.Collections.Generic.ICollection<Customer> Customers { get; set; } = new System.Collections.Generic.List<Customer>(); // Many to many mapping
1105+
public virtual System.Collections.Generic.ICollection<Customer> Customers { get; set; } // Many to many mapping
11061106

11071107
public CustomerDemographic()
11081108
{
@@ -1138,15 +1138,15 @@ public class Employee
11381138
/// <summary>
11391139
/// Child Employees where [Employees].[ReportsTo] point to this entity (FK_Employees_Employees)
11401140
/// </summary>
1141-
public virtual System.Collections.Generic.ICollection<Employee> Employees { get; set; } = new System.Collections.Generic.List<Employee>(); // Employees.FK_Employees_Employees
1141+
public virtual System.Collections.Generic.ICollection<Employee> Employees { get; set; } // Employees.FK_Employees_Employees
11421142
/// <summary>
11431143
/// Child Orders where [Orders].[EmployeeID] point to this entity (FK_Orders_Employees)
11441144
/// </summary>
1145-
public virtual System.Collections.Generic.ICollection<Order> Orders { get; set; } = new System.Collections.Generic.List<Order>(); // Orders.FK_Orders_Employees
1145+
public virtual System.Collections.Generic.ICollection<Order> Orders { get; set; } // Orders.FK_Orders_Employees
11461146
/// <summary>
11471147
/// Child Territories (Many-to-Many) mapped by table [EmployeeTerritories]
11481148
/// </summary>
1149-
public virtual System.Collections.Generic.ICollection<Territory> Territories { get; set; } = new System.Collections.Generic.List<Territory>(); // Many to many mapping
1149+
public virtual System.Collections.Generic.ICollection<Territory> Territories { get; set; } // Many to many mapping
11501150

11511151
// Foreign keys
11521152

@@ -1219,7 +1219,7 @@ public class Order
12191219
/// <summary>
12201220
/// Child OrderDetails where [Order Details].[OrderID] point to this entity (FK_Order_Details_Orders)
12211221
/// </summary>
1222-
public virtual System.Collections.Generic.ICollection<OrderDetail> OrderDetails { get; set; } = new System.Collections.Generic.List<OrderDetail>(); // Order Details.FK_Order_Details_Orders
1222+
public virtual System.Collections.Generic.ICollection<OrderDetail> OrderDetails { get; set; } // Order Details.FK_Order_Details_Orders
12231223

12241224
// Foreign keys
12251225

@@ -1339,7 +1339,7 @@ public class Product
13391339
/// <summary>
13401340
/// Child OrderDetails where [Order Details].[ProductID] point to this entity (FK_Order_Details_Products)
13411341
/// </summary>
1342-
public virtual System.Collections.Generic.ICollection<OrderDetail> OrderDetails { get; set; } = new System.Collections.Generic.List<OrderDetail>(); // Order Details.FK_Order_Details_Products
1342+
public virtual System.Collections.Generic.ICollection<OrderDetail> OrderDetails { get; set; } // Order Details.FK_Order_Details_Products
13431343

13441344
// Foreign keys
13451345

@@ -1415,7 +1415,7 @@ public class Region
14151415
/// <summary>
14161416
/// Child Territories where [Territories].[RegionID] point to this entity (FK_Territories_Region)
14171417
/// </summary>
1418-
public virtual System.Collections.Generic.ICollection<Territory> Territories { get; set; } = new System.Collections.Generic.List<Territory>(); // Territories.FK_Territories_Region
1418+
public virtual System.Collections.Generic.ICollection<Territory> Territories { get; set; } // Territories.FK_Territories_Region
14191419

14201420
public Region()
14211421
{
@@ -1456,7 +1456,7 @@ public class Shipper
14561456
/// <summary>
14571457
/// Child Orders where [Orders].[ShipVia] point to this entity (FK_Orders_Shippers)
14581458
/// </summary>
1459-
public virtual System.Collections.Generic.ICollection<Order> Orders { get; set; } = new System.Collections.Generic.List<Order>(); // Orders.FK_Orders_Shippers
1459+
public virtual System.Collections.Generic.ICollection<Order> Orders { get; set; } // Orders.FK_Orders_Shippers
14601460

14611461
public Shipper()
14621462
{
@@ -1504,7 +1504,7 @@ public class Supplier
15041504
/// <summary>
15051505
/// Child Products where [Products].[SupplierID] point to this entity (FK_Products_Suppliers)
15061506
/// </summary>
1507-
public virtual System.Collections.Generic.ICollection<Product> Products { get; set; } = new System.Collections.Generic.List<Product>(); // Products.FK_Products_Suppliers
1507+
public virtual System.Collections.Generic.ICollection<Product> Products { get; set; } // Products.FK_Products_Suppliers
15081508

15091509
public Supplier()
15101510
{
@@ -1525,7 +1525,7 @@ public class Territory
15251525
/// <summary>
15261526
/// Child Employees (Many-to-Many) mapped by table [EmployeeTerritories]
15271527
/// </summary>
1528-
public virtual System.Collections.Generic.ICollection<Employee> Employees { get; set; } = new System.Collections.Generic.List<Employee>(); // Many to many mapping
1528+
public virtual System.Collections.Generic.ICollection<Employee> Employees { get; set; } // Many to many mapping
15291529

15301530
// Foreign keys
15311531

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3255,7 +3255,7 @@ SELECT SERVERPROPERTY('Edition') AS Edition,
32553255
return ForeignKeyName(tableNameHumanCase, foreignKey, fkName, relationship, 6);
32563256
}
32573257

3258-
public void AddReverseNavigation(Relationship relationship, string fkName, Table fkTable, string propName, string constraint, string collectionType, CommentsStyle includeComments, List<ForeignKey> fks, Table mappingTable=null)
3258+
public void AddReverseNavigation(Relationship relationship, string fkName, Table fkTable, string propName, string constraint, string collectionType, CommentsStyle includeComments, List<ForeignKey> fks, Table mappingTable = null)
32593259
{
32603260
string fkNames = "";
32613261
switch (relationship)
@@ -3288,13 +3288,15 @@ SELECT SERVERPROPERTY('Edition') AS Edition,
32883288
new PropertyAndComments()
32893289
{
32903290
Definition = string.Format("public virtual {0} {1} {{ get; set; }}{2}", fkTable.NameHumanCaseWithSuffix, propName, includeComments != CommentsStyle.None ? " // " + constraint : string.Empty),
3291-
Comments = string.Format("Parent {0} pointed by [{1}].{2} ({3})", this.NameHumanCaseWithSuffix, fkTable.Name, fkNames, fks.First().ConstraintName)
3291+
Comments = string.Format("Parent {0} pointed by [{1}].{2} ({3})", NameHumanCaseWithSuffix, fkTable.Name, fkNames, fks.First().ConstraintName)
32923292
}
32933293
);
32943294
break;
32953295

32963296
case Relationship.ManyToOne:
3297-
var initialization1 = string.Format(" = new {0}<{1}>();", collectionType, fkTable.NameHumanCaseWithSuffix);
3297+
string initialization1 = string.Empty;
3298+
if(UsePropertyInitializers)
3299+
initialization1 = string.Format(" = new {0}<{1}>();", collectionType, fkTable.NameHumanCaseWithSuffix);
32983300
ReverseNavigationProperty.Add(
32993301
new PropertyAndComments()
33003302
{
@@ -3306,12 +3308,14 @@ SELECT SERVERPROPERTY('Edition') AS Edition,
33063308
break;
33073309

33083310
case Relationship.ManyToMany:
3309-
var initialization2 = string.Format(" = new {0}<{1}>();", collectionType, fkTable.NameHumanCaseWithSuffix);
3311+
string initialization2 = string.Empty;
3312+
if(UsePropertyInitializers)
3313+
initialization2 = string.Format(" = new {0}<{1}>();", collectionType, fkTable.NameHumanCaseWithSuffix);
33103314
ReverseNavigationProperty.Add(
33113315
new PropertyAndComments()
33123316
{
33133317
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),
3314-
Comments = string.Format("Child {0} (Many-to-Many) mapped by table [{1}]", Inflector.MakePlural(fkTable.NameHumanCase), mappingTable.Name)
3318+
Comments = string.Format("Child {0} (Many-to-Many) mapped by table [{1}]", Inflector.MakePlural(fkTable.NameHumanCase), mappingTable == null ? string.Empty : mappingTable.Name)
33153319
}
33163320
);
33173321

0 commit comments

Comments
 (0)