We are developing with Visual Studio 2013, Entity Framework 5, Oracle DB 11 via ODP.NET managed driver.
The edmx is generated/updated from database (database first). We generate POCO object using standard T4.
We have 2 tables with a master-detail foreign key relation, one to many. The foreign key in database does _not_ allow cascade deletes, so when you delete master row via SQL, you get error " ... child record found ... ".
The problem now is:
In Entity Framework, when i delete a record from the master table, then EF also deletes all corresponding detail records from the detail table! The restriction of the foreign key in database is ignored.
In edmx diagram, the properies End1 OnDelete / End2 OnDelete are set to "None", so i expect that on delete of a master row, EF should throw an error if detail rows exists.
How can i disable the cascading of the delete?
Here is the FK definition in edmx:
<Association Name="USR_USER_ROLES_ROLES_FK">
<End Role="USR_ROLES" Type="Self.USR_ROLES" Multiplicity="1" />
<End Role="USR_USER_ROLES" Type="Self.USR_USER_ROLES" Multiplicity="*" />
<ReferentialConstraint>
<Principal Role="USR_ROLES">
<PropertyRef Name="GES" />
<PropertyRef Name="PROJ" />
<PropertyRef Name="ROLE_NAME" />
</Principal>
<Dependent Role="USR_USER_ROLES">
<PropertyRef Name="GES" />
<PropertyRef Name="PROJ" />
<PropertyRef Name="ROLE_NAME" />
</Dependent>
</ReferentialConstraint>
</Association>
The delete of master row is done by calling:
ivDbCtx.USR_Roles.Local.Remove(role); // ivDbCtx is the DbContext, USR_Roles is the collection, role is the POCO object to be deleted.
Thank you very much for your help!
Udo