Avatar of deanlee17
 asked on

Entity Data Model saving data

Hi Experts,

I think im missing something simple. I have created an entity data model that gets filled from an SQL server database, filled 2 datagrids using the tables in the data model. How do I get any changes within the grid to fire back into my SQL server database?

My (generated) code so far is....

 Private Function GetWPFtblSmartQuoteHeadersQuery(OMSystemEntities As hello.OMSystemEntities) As System.Data.Objects.ObjectQuery(Of hello.WPFtblSmartQuoteHeader)

        Dim WPFtblSmartQuoteHeadersQuery As System.Data.Objects.ObjectQuery(Of hello.WPFtblSmartQuoteHeader) = OMSystemEntities.WPFtblSmartQuoteHeaders
        'Update the query to include WPFtblSmartQuoteLines data in WPFtblSmartQuoteHeaders. You can modify this code as needed.
        WPFtblSmartQuoteHeadersQuery = WPFtblSmartQuoteHeadersQuery.Include("WPFtblSmartQuoteLines")
        'Returns an ObjectQuery.
        Return WPFtblSmartQuoteHeadersQuery
    End Function

    Private Sub Window_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded

        Dim OMSystemEntities As hello.OMSystemEntities = New hello.OMSystemEntities()
        'Load data into WPFtblSmartQuoteHeaders. You can modify this code as needed.
        Dim WPFtblSmartQuoteHeadersViewSource As System.Windows.Data.CollectionViewSource = CType(Me.FindResource("WPFtblSmartQuoteHeadersViewSource"), System.Windows.Data.CollectionViewSource)
        Dim WPFtblSmartQuoteHeadersQuery As System.Data.Objects.ObjectQuery(Of hello.WPFtblSmartQuoteHeader) = Me.GetWPFtblSmartQuoteHeadersQuery(OMSystemEntities)
        WPFtblSmartQuoteHeadersViewSource.Source = WPFtblSmartQuoteHeadersQuery.Execute(System.Data.Objects.MergeOption.AppendOnly)
    End Sub

Many Thanks.
.NET ProgrammingVisual Basic.NETMicrosoft Development

Avatar of undefined
Last Comment

8/22/2022 - Mon
Nasir Razzaq


Blimey, I thought it would be easier than this, i assumed EDM would just keep firing updates into the database....

First link does use ERM but then codes another connection to the database?! I thought when you have an EDM this connection can be used for all database interactions?

second link, no use.

third link, look at it now.
Nasir Razzaq

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Excellen, Cheers mate.
Your help has saved me hundreds of hours of internet surfing.