I have two entities: (Entity Framework code first approach)
public class Work
{
public Guid Id { get; set; }
public string Title { get; set; }
public virtual Department Department { get; set; }
public virtual Guid DepartmentId { get; set; }
}
public class Department
{
public Department()
{
Works = new ObservableCollection<Work>();
}
public Guid Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Work> Works { get; private set; }
}
And I have the following XAML: (DataGrid Work item)
(I want to display a DataGridComboBoxColumn
which would contain all Department names)
<DataGrid.Columns>
<DataGridTextColumn x:Name="idColumn5" Binding="{Binding Id}" Header="Id" Width="100"/>
<DataGridTextColumn x:Name="titleColumn2" Binding="{Binding Title}" Header="Title" Width="250"/>
<DataGridComboBoxColumn SelectedValueBinding="{Binding Path=Department.Name, Mode=TwoWay,
NotifyOnTargetUpdated=True}" Header="Department Name"
ItemsSource="{x:Static my:MainWindow.Departments}"
DisplayMemberPath="Name" SelectedValuePath="ID"
Width="140"/>
<DataGridTextColumn x:Name="priceColumn2" Binding="{Binding Price}" Header="Price" Width="90"/>
</DataGrid.Columns>
VS 2012 outlines (error) the ItemsSource="{x:Static my:MainWindow.Departments}"
:
Invalid object name 'dbo.Departments'.
But I can start the project.
When I'm trying to add new Work I get (inner inner exception):
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.Works_dbo.Departments_DepartmentId". The conflict occurred in database "MyDbName", table "dbo.Departments", column 'id'.
Also I have this property in MainWindow object:
public static ICollection<Department> Departments
{
get
{
if (System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv")
return new List<Department>();
return _context.Departments.ToList();
}
}
I'm new to WPF and this type of data binding and XAML too.
Will appretiate any answer that can help solve the problem.