locked
EF6 Code-First and WPF Combo Box RRS feed

  • Question

  • I am having some unintended issues with my ComboBox in WPF.  I have a Job Entity setup in my code like this:

            public class Job
            {
                public int Id { get; set; }
                public string Name { get; set; }
                public string BidNumber { get; set; }
                public string Address { get; set; }
                public string Address2 { get; set; }
                public string City { get; set; }
                public string State { get; set; }
                public int Zip { get; set; }
                [Required]
                public Status Status { get; set; }

            }

    And the related Status Entity setup below:

            public class Status
            {
                public int Id { get; set; }
                public string Name { get; set; }
                public ICollection<Job> Jobs { get; set; }
            }

    My Combo Box is setup per below in XAML:

    <ComboBox  x:Name="StatusMenu" ItemsSource="{Binding TheseStatus}" DisplayMemberPath="Name" SelectedItem="{Binding ThisJob.Status}" Grid.Column="2" Grid.Row="8" Grid.ColumnSpan="3" Margin="2" BorderBrush="#FFABADB3" Background="White"/>

    The Combobox is populating the list of statuses, correctly, however, on my detail window, when I select the status, and call savechanges, instead of creating the link to the selected status, it is adding another status of the same name to the status table, and linking to it.  I am at a loss, and can't figure out what is going on.  Any ideas?

    Wednesday, October 26, 2016 2:40 PM

Answers

  • >>The Combobox is populating the list of statuses, correctly, however, on my detail window, when I select the status, and call savechanges, instead of creating the link to the selected status, it is adding another status of the same name to the status table, and linking to it.  I am at a loss, and can't figure out what is going on.  Any ideas?


    How your entities get saved to the database has nothing to with WPF. This is an Entity Framework question that should be asked in the EF forum: https://social.msdn.microsoft.com/Forums/en-US/home?forum=adodotnetentityframework

    Make sure that you always include all relevant code snippets that are required for someone else to reproduce your issue from scratch when starting a new thread. You could also upload a sample project to OneDrive and post the link to it here.

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    • Marked as answer by RMillsFe Thursday, October 27, 2016 2:01 AM
    Wednesday, October 26, 2016 8:49 PM

All replies

  • >>The Combobox is populating the list of statuses, correctly, however, on my detail window, when I select the status, and call savechanges, instead of creating the link to the selected status, it is adding another status of the same name to the status table, and linking to it.  I am at a loss, and can't figure out what is going on.  Any ideas?


    How your entities get saved to the database has nothing to with WPF. This is an Entity Framework question that should be asked in the EF forum: https://social.msdn.microsoft.com/Forums/en-US/home?forum=adodotnetentityframework

    Make sure that you always include all relevant code snippets that are required for someone else to reproduce your issue from scratch when starting a new thread. You could also upload a sample project to OneDrive and post the link to it here.

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    • Marked as answer by RMillsFe Thursday, October 27, 2016 2:01 AM
    Wednesday, October 26, 2016 8:49 PM
  • Thanks, so much, I will post in the appropriate forum!
    Thursday, October 27, 2016 2:01 AM