Link to home
Start Free TrialLog in
Avatar of deanlee17
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.
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Avatar of deanlee17
deanlee17

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellen, Cheers mate.