Customer_TaxExemptStates
Customer_Id int
StateProvince_Id int
Added this to Core.Domain.Customers.Customer:
public virtual ICollection<StateProvince> TaxExemptStates
{
get { return _taxExemptStates ?? (_taxExemptStates = new List<StateProvince>()); }
protected set { _taxExemptStates = value; }
}
Wired it up in the Map class:
this.HasMany(c => c.TaxExemptStates)
.WithMany()
.Map(m => m.ToTable("Customer_TaxExemptStates"));
Then in a ITask I made, I'm trying to add states to the list:
StateProvince state = _stateProvinceService.GetStateProvinceByAbbreviation(stateCode);
customer.TaxExemptStates.Add(state);
_customerService.UpdateCustomer(customer);
I get an exception on the .Add line saying that the two objects belong to different contexts. Any ideas? If I change it to adding a new StateProvince to the list with the fields from state, it works but I get a new StateProvince in my table.