My code-first EF6 Order entity looks like following:
public partial class Order
{
...
public int DispatchMethodID { get; set; }
public virtual DispatchMethod DispatchMethod { get; set; }
...
}
The corresponding code in the DbContext:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
...
modelBuilder.Entity<DispatchMethod>()
.HasMany(e => e.Orders)
.WithRequired(e => e.DispatchMethod)
.HasForeignKey(e => e.DispatchMethodID)
.WillCascadeOnDelete(false);
...
}
The DispatchMethod class looks like this:
public partial class DispatchMethod
{
public DispatchMethod()
{
Orders = new HashSet<Order>();
}
public int DispatchMethodID { get; set; }
[Required]
[StringLength(100)]
public string Name { get; set; }
public virtual ICollection<Order> Orders { get; set; }
...
}
Now, I want to bind both my _Order's DispatchMethod AND DispatchMethodID to the selected value of a combobox:
cmbMethod.DataBindings.Add("SelectedValue", _Order, "DispatchMethodID");
However, given code only updates the DispatchMethodID property, but does not affect DispatchMethod navigation property value. What is the best practice and how should I accomplish this?
Any help appreciated.
Aucun commentaire:
Enregistrer un commentaire