Solved

Delete multiple rows in Entity Framework

Posted on 2014-01-23
1
543 Views
Last Modified: 2014-01-24
Can someone help me showing me how to iterate through each child record using the parent key (coming from DataKey)

This is my code, so far I am able to firgure out how to get the children records (well the first one because there is no iteration):

Protected Sub DeleteAllChildren()

    Dim myContext As New OLTPEntities
    Dim myRecipeSteps = myContext.RefineRecipeStep.Where("it.Recipe_Id=" & Me.dvRecipeItem.DataKey(0)).First()

    Dim strRecipeSteps = New StringBuilder("")

    strRecipeSteps.Append("[ID]=" & myRecipeSteps.Id & ", ")
    strRecipeSteps.Append("[Recipe_Id]=" & myRecipeSteps.Recipe_Id & ", ")
    strRecipeSteps.Append("[Recipe_ItemNumber]=" & myRecipeSteps.Recipe_ItemNumber & ", ")
    strRecipeSteps.Append("[Recipe_VersionNumber]=" & myRecipeSteps.Recipe_VersionNumber & ", ")
    strRecipeSteps.Append("[ProcessType]=" & myRecipeSteps.ProcessType & ", ")
    strRecipeSteps.Append("[AdditionOrder]=" & myRecipeSteps.AdditionOrder & ", ")
    strRecipeSteps.Append("[IngredientItemNumber]=" & myRecipeSteps.IngredientItemNumber & ", ")
    strRecipeSteps.Append("[AdditionType]=" & myRecipeSteps.AdditionType & ", ")
    strRecipeSteps.Append("[RecipePercent]=" & myRecipeSteps.RecipePercent)

    End Sub

Open in new window



Any help is kindly appreciated.

Thank you.
0
Comment
Question by:metropia
1 Comment
 
LVL 27

Accepted Solution

by:
Ark earned 500 total points
Comment Utility
Dim myRecipeSteps = myContext.RefineRecipeStep.Where("it.Recipe_Id=" & Me.dvRecipeItem.DataKey(0)) '<=== remove First()
For each myStep In myRecipeSteps
Next
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now