Skip to content

Commit 54a3cdb

Browse files
committed
#216 Futher update required. Thanks to Richard Drizin.
1 parent 8bf8199 commit 54a3cdb

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,17 +361,18 @@
361361

362362
// FK_TableName_FromThisToParentRelationshipName_FromParentToThisChildsRelationshipName
363363
// (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)
364+
// Feel free to use and change the following
365+
/*if (foreignKey.ConstraintName.StartsWith("FK_") && foreignKey.ConstraintName.Count(x => x == '_') == 3)
365366
{
366367
var parts = foreignKey.ConstraintName.Split('_');
367-
if (!string.IsNullOrWhiteSpace(parts[2]) && !string.IsNullOrWhiteSpace(parts[3]))
368+
if (!string.IsNullOrWhiteSpace(parts[2]) && !string.IsNullOrWhiteSpace(parts[3]) && parts[1] == foreignKey.FkTableName)
368369
{
369370
if (relationship == Relationship.OneToMany)
370371
fkName = parts[3];
371372
else if (relationship == Relationship.ManyToOne)
372373
fkName = parts[2];
373374
}
374-
}
375+
}*/
375376

376377
return fkName;
377378
};

EntityFramework.Reverse.POCO.Generator/Database.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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> Orders { 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; } = new System.Collections.Generic.List<OrderDetail>(); // Order Details.FK_Order_Details_Orders
12231223

12241224
// Foreign keys
12251225

@@ -1239,7 +1239,7 @@ public class Order
12391239
public Order()
12401240
{
12411241
Freight = 0m;
1242-
Orders = new System.Collections.Generic.List<OrderDetail>();
1242+
OrderDetails = new System.Collections.Generic.List<OrderDetail>();
12431243
}
12441244
}
12451245

@@ -1258,11 +1258,11 @@ public class OrderDetail
12581258
/// <summary>
12591259
/// Parent Order pointed by [Order Details].([OrderId]) (FK_Order_Details_Orders)
12601260
/// </summary>
1261-
public virtual Order Details1 { get; set; } // FK_Order_Details_Orders
1261+
public virtual Order Order { get; set; } // FK_Order_Details_Orders
12621262
/// <summary>
12631263
/// Parent Product pointed by [Order Details].([ProductId]) (FK_Order_Details_Products)
12641264
/// </summary>
1265-
public virtual Product Details2 { get; set; } // FK_Order_Details_Products
1265+
public virtual Product Product { get; set; } // FK_Order_Details_Products
12661266

12671267
public OrderDetail()
12681268
{
@@ -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> Products { 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; } = new System.Collections.Generic.List<OrderDetail>(); // Order Details.FK_Order_Details_Products
13431343

13441344
// Foreign keys
13451345

@@ -1359,7 +1359,7 @@ public Product()
13591359
UnitsOnOrder = 0;
13601360
ReorderLevel = 0;
13611361
Discontinued = false;
1362-
Products = new System.Collections.Generic.List<OrderDetail>();
1362+
OrderDetails = new System.Collections.Generic.List<OrderDetail>();
13631363
}
13641364
}
13651365

@@ -1849,8 +1849,8 @@ public OrderDetailConfiguration(string schema)
18491849
Property(x => x.Discount).HasColumnName(@"Discount").HasColumnType("real").IsRequired();
18501850

18511851
// Foreign keys
1852-
HasRequired(a => a.Details1).WithMany(b => b.Orders).HasForeignKey(c => c.OrderId).WillCascadeOnDelete(false); // FK_Order_Details_Orders
1853-
HasRequired(a => a.Details2).WithMany(b => b.Products).HasForeignKey(c => c.ProductId).WillCascadeOnDelete(false); // FK_Order_Details_Products
1852+
HasRequired(a => a.Order).WithMany(b => b.OrderDetails).HasForeignKey(c => c.OrderId).WillCascadeOnDelete(false); // FK_Order_Details_Orders
1853+
HasRequired(a => a.Product).WithMany(b => b.OrderDetails).HasForeignKey(c => c.ProductId).WillCascadeOnDelete(false); // FK_Order_Details_Products
18541854
}
18551855
}
18561856

EntityFramework.Reverse.POCO.Generator/Database.tt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,17 +415,18 @@
415415

416416
// FK_TableName_FromThisToParentRelationshipName_FromParentToThisChildsRelationshipName
417417
// (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)
418+
// Feel free to use and change the following
419+
/*if (foreignKey.ConstraintName.StartsWith("FK_") && foreignKey.ConstraintName.Count(x => x == '_') == 3)
419420
{
420421
var parts = foreignKey.ConstraintName.Split('_');
421-
if (!string.IsNullOrWhiteSpace(parts[2]) && !string.IsNullOrWhiteSpace(parts[3]))
422+
if (!string.IsNullOrWhiteSpace(parts[2]) && !string.IsNullOrWhiteSpace(parts[3]) && parts[1] == foreignKey.FkTableName)
422423
{
423424
if (relationship == Relationship.OneToMany)
424425
fkName = parts[3];
425426
else if (relationship == Relationship.ManyToOne)
426427
fkName = parts[2];
427428
}
428-
}
429+
}*/
429430

430431
return fkName;
431432
};

0 commit comments

Comments
 (0)