none
WPF and EF - reuse entity for another window? RRS feed

  • Question

  • I used the EF wizard to create an entity to bind a master/detail window and am wondering if I can reuse the entity for another window.  The master/detail window shows patients (name only) and their dentist and hygenist appointments.  I put a menu at the top for the user to open a window that (will) show the selected patients' demographic info (address, city, etc.)

    I've got the demographics window created but am not sure how to bind it properly.  The entity for the master/detail window is like so:

    I tried using the same code to bind the demographics window as the master/detail window, but the demographics window displays blanks.

    Code for master/detail:

            Dim TblPatientDemographicViewSource As System.Windows.Data.CollectionViewSource =
                CType(Me.FindResource("TblPatientDemographicViewSource"), System.Windows.Data.CollectionViewSource)
    
            'sort view by patient name.  
            TblPatientDemographicViewSource.SortDescriptions.Add(New SortDescription("PatientName", ListSortDirection.Ascending))
    
            'Load data by setting the CollectionViewSource.Source property:
            'TblPatientDemographicViewSource.Source = [generic data source]
            _context.tblPatientDemographics.Load()
            TblPatientDemographicViewSource.Source = _context.tblPatientDemographics.Local

    Code for demographics window:

            Dim PatientDemographicsViewSource As System.Windows.Data.CollectionViewSource =
                CType(Me.FindResource("TblPatientDemographicViewSource"), System.Windows.Data.CollectionViewSource)
            _PatientDemographicsContext.tblPatientDemographics.Load()
            PatientDemographicsViewSource.Source = _PatientDemographicsContext.tblPatientDemographics.Local
    
            'Load data by setting the CollectionViewSource.Source property:
            'TblPatientDemographicViewSource.Source = [generic data source]
            _PatientDemographicsContext.tblPatientDemographics.Load()
            PatientDemographicsViewSource.Source = _PatientDemographicsContext.tblPatientDemographics.Local
    

    No difference between the two other than slight name changes and no sort description. 


    Thanks.

    Thursday, December 5, 2013 9:27 PM

Answers

  • Hello,

    >> am wondering if I can reuse the entity for another window

    Yes, this is completely possible. It is same that if we band an entity to a datagridview in a form and band the entity to anther datagridview in a different form.

    The codes seem to be ok.

    Have a try to in this line of code to make a break below to see whether it has load the data to local.

    _PatientDemographicsContext.tblPatientDemographics.Load()

    If it has no data to be loaded to local, please mark sure that the PatientDemographicsContext is active and if it is possible, please share that how you define the PatientDemographicsContext object.

    If it has data, it may be a WPF issue, for this, I suggest you posting this issue to the WPF forum:

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=wpf

    Regards.


    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.

    • Marked as answer by db_dweeb Friday, December 6, 2013 4:36 PM
    Friday, December 6, 2013 8:31 AM
    Moderator

All replies

  • Hello,

    >> am wondering if I can reuse the entity for another window

    Yes, this is completely possible. It is same that if we band an entity to a datagridview in a form and band the entity to anther datagridview in a different form.

    The codes seem to be ok.

    Have a try to in this line of code to make a break below to see whether it has load the data to local.

    _PatientDemographicsContext.tblPatientDemographics.Load()

    If it has no data to be loaded to local, please mark sure that the PatientDemographicsContext is active and if it is possible, please share that how you define the PatientDemographicsContext object.

    If it has data, it may be a WPF issue, for this, I suggest you posting this issue to the WPF forum:

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=wpf

    Regards.


    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.

    • Marked as answer by db_dweeb Friday, December 6, 2013 4:36 PM
    Friday, December 6, 2013 8:31 AM
    Moderator
  • Sorry, I thought I had posted to the WPF forum.

    Data is loaded so it must be a WPF issue.

    Thanks.


    Thanks.

    Friday, December 6, 2013 4:36 PM