locked
Problem to changed association value. RRS feed

  • Question

  • Hi
    with thanks to microsoft to provide EF to simplify data-centric applications, but after a few months working on EF 1.0, i didn't found useful and practical tutorials and articles to demonstrate how to bind entities and its associations to dataGridView and data aware controls and detect association changed when value has been changed on dataGridViewComboBox or other controls. i also i still have problem in EF 4.0, for example we have a dataGridView and comboBox which display Orders from northwind database and for each order, that comboBox display Customer.CompanyName as follow :

     this.orderBindingSource.DataSource = this.db.Orders.Include("Customer").Include("Employee").ToList();
    
    
    
     this.customerBindingSource.DataSource = this.db.Customers.ToList();
    
    
    
     
    
    
    
     this.comboBox1.DisplayMember = "CompanyName";
    
    
    
     this.comboBox1.ValueMember = "CustomerID";
    
    
    
     this.comboBox1.DataBindings.Add("SelectedValue", this.orderBindingSource, "Customer.CustomerID");
    
    
    
    

    notice that comboBox1.DataSource sets to customerBindingSource.

    my problem is that when i change companyName of selected order from comboBox1, i got this error :

    The property 'CustomerID' is part of the object's key information and cannot be modified.

    where does the prolem and how to solve it ?
    thanks
    http://www.codeproject.com/KB/codegen/DatabaseHelper.aspx
    Thursday, November 5, 2009 7:00 PM

Answers