Using Visual Studio 2008 SP1 and .NET 3.5 SP1. I have a simple test project with 2 tables, PARENT and CHILD, linked by foreign key. I created the ADO.NET Entity Data Model, and named the relationship that represents the database foreign key (FK_PARENT) to Children in the PARENT entity. My goal here is to bind a grid control to PARENT.Children so the user is editing only child records for the selected parent, and in this case, it is a new PARENT record.
I have a WPF form, with 2 tabs, tab1 and tab2.
tab1 has some fields where I capture data for PARENT, then on tab2 I have a Telerik RadGridView control, bound to parent.Child (which is the association that represents the foreign key from CHILD -> PARENT).
1) I enter the data, then click tab2 (which causes tab1's LostFocus event to fire and I call entities.AddToParent(parent)
2) I use the insert key (for the Telerik RadGridView) which calls the AddingNewDataItem event, which indeed ends up adding the records to my CHILD table just fine.
3) The inserted record has the correct PARENT key.
PROBLEM: The grid shows a new empty row, with no columns, period. Just an empty grid. The database record is actually correct, however.
If I bind the grid directly to entities.CHILD, I see all CHILD columns correctly. It is the binding to the relationship that causes this problem.
To alleviate the data provider, I tested both on SQL Server and SQL Anywhere 11, but get the same results.
Essentially, I have a parent entity in scope, I want to add child entities, and I want a bound control to show those immediately, and also to allow editing.
Code here:
Help.
I have a WPF form, with 2 tabs, tab1 and tab2.
tab1 has some fields where I capture data for PARENT, then on tab2 I have a Telerik RadGridView control, bound to parent.Child (which is the association that represents the foreign key from CHILD -> PARENT).
1) I enter the data, then click tab2 (which causes tab1's LostFocus event to fire and I call entities.AddToParent(paren
2) I use the insert key (for the Telerik RadGridView) which calls the AddingNewDataItem event, which indeed ends up adding the records to my CHILD table just fine.
3) The inserted record has the correct PARENT key.
PROBLEM: The grid shows a new empty row, with no columns, period. Just an empty grid. The database record is actually correct, however.
If I bind the grid directly to entities.CHILD, I see all CHILD columns correctly. It is the binding to the relationship that causes this problem.
To alleviate the data provider, I tested both on SQL Server and SQL Anywhere 11, but get the same results.
Essentially, I have a parent entity in scope, I want to add child entities, and I want a bound control to show those immediately, and also to allow editing.
Code here:
public partial class Window1 : Window { Entities entities; PARENT parent; bool saved = false; public Window1() { InitializeComponent(); entities = new Entities(); parent = PARENT.CreatePARENT(Guid.NewGuid().ToString(), "00000"); gridViewChild.ItemsSource = parent.Child; } private void buttonOk_Click(object sender, RoutedEventArgs e) { entities.SaveChanges(); } private void buttonCancel_Click(object sender, RoutedEventArgs e) { } private void tabItemParent_LostFocus(object sender, RoutedEventArgs e) { if (!saved) { // Create the parent parent.FIRST_NAME = this.textBoxFirstName.Text; parent.LAST_NAME = this.textBoxLastName.Text; parent.MIDDLE_NAME = this.textBoxMiddleName.Text; parent.ZIP = this.textBoxZipCode.Text; entities.AddToPARENT(parent); saved = true; } } private void gridViewChild_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e) { // Entity Framework supports identity (server side generated) keys but we // must provide a default key value first. CHILD child = CHILD.CreateCHILD(0, "Test"); parent.ChildProfile.Add(child); e.NewObject = child; } } |
Help.