Sitemap

Amicuk Programming Answers

EF database first cascades delete despite cascade is restricted in db and edmx setting End1/2 OnDelete = "None"

-0001-11-30   Views:2

Advertisement

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 for

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

The replay answer
Advertisement
Hello,
For issues regarding ODP.NET managed driver, I would suggest you posting to oracle entity framework forum:
https://community.oracle.com/communications
There are oracle entity framework expects who will help you better.
Thanks for your understanding.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.

Go to See the other 2 answers

Hot
In the attached vi, the one second loop runs at one second and can't be touched.  In the ten second loop, the ten second clock is a stand in for a process that generates a finished signal. The problem is once the process is complete, to start it agai [More]
I installed the 64bit system and then KDE but when I start KDE the screen freezes and I have to reboot, any ideas Last edited by normc (2009-04-06 19:23:01)is xorg working properly, what graphics driver are you using? also, is the hal daemon running? [More]
Hello everyone, I'm encountering an issue on the alignment of the rate display in Project Server Resource Center: As you can see the rate reflected in the resource center is not the one which should be based on what we see in MS Project. the rate is [More]
Hi, I need to create spot color in Illustrator CS4 with js, with assigned name and color values. Here what I have: myColor = myDoc.spots.add({name:"FOIL", colorValue:[10, 0, 100, 0]}); But it comes out as process instead of spot and the color is [More]
Hello friends, How to write SAPscript print program for multiple pages? please help me. Thanks and regards, Shivanand.I believe you have posted this question in the wrong forum.  There is an ABAP Forms Printing Forum.Read other 2 answers [More]
well yesterday i hooked up my ipod to an old computer (Gateway EV700?) that has new applications like windows xp and all the new versions of quicktime and itunes and popped the ipod on the cable and popped it into a usb port on the front on the compu [More]
My wife misplaced her iPhone this weekend and didn't have her computer with her and doesn't own an iPad. she had no way to access Find iPhone app. if we could easily add each other's devices to each other's Find iPhone app, we'd be able to assist eac [More]
I have an older Apple LCD display with the ADC connector, which I can use with my (even older) PowerMac. It's a great monitor, and I'd hate to have it just sit around when I upgrade...hopefully to an iMac. I know there are connectors for mini-DVI to [More]
Hi, I would like to ask where does the billing date of the invoice (billing type F2) is copied. Is it copied on the actual goods issue date? If that is the case, how about the billing date of an intercompany invoice ( billing type IV), from where doe [More]
hi friends. i have a site published at .mac , for some reason my site isnt showing up anymore when i open iweb, anybody know how i can get this site back to iweb so i can edit it....thanksThomas This is my suggestion. 1. Take your domain.sites file, [More]