Solved

Delete multiple rows in Entity Framework

Posted on 2014-01-23
1
547 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
ID: 39805497
Dim myRecipeSteps = myContext.RefineRecipeStep.Where("it.Recipe_Id=" & Me.dvRecipeItem.DataKey(0)) '<=== remove First()
For each myStep In myRecipeSteps
Next
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

16 Experts available now in Live!

Get 1:1 Help Now