Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

Created Issue: Reverse engineering feature does not honor cascade delete settings for foreign keys [878]

$
0
0
Reverse engineering feature does not honor cascade delete settings for foreign keys.

If FK1 has Delete Rule set to No Action in SQL Server, the following mapping is generated.

```
this.HasRequired(t => t.Entity)
.WithMany(t => t.RelatedEntities)
.HasForeignKey(d => d.EntityId);
```

This implies delete on cascade which goes against what the database was originally designed to do. It should be generating the following...

this.HasRequired(t => t.Entity)
.WithMany(t => t.RelatedEntities)
.HasForeignKey(d => d.EntityId)
.WillCascadeOnDelete(false);

To work around this I customized the T4 template. I set a bool as follows

```
bool cascadeDelete = navProperty.ToEndMember.DeleteBehavior == System.Data.Metadata.Edm.OperationAction.Cascade;
```

Then added the .WillCascadeOnDelete() method based according to the value in the bool. T4 is attached.

Viewing all articles
Browse latest Browse all 10318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>