I have the following entities:
- BIEntities db = new BIEntities();
-
- public class SALES
- {
- public int IDs {get; set;}
- public string product { get; set; }
- ICollection<COUNTRIES> COUNTRIES { get; set; }
- }
- public class COUNTRIES
- {
- public int IDc { get; set; }
- public string country { get; set; }
- public virtual SALES SALES { get; set; }
- }
And a ViewModel:
- public class myViewModel
- {
- public int ID { get; set; }
- public string product { get; set; }
- List<string> country { get; set; }
- }
I am trying to update (edit) all entities from myViewModel:
- SALES sUpdate = db.SALES.FirstOrDefault(s => s.IDs == myModel.ID);
- if (sUpdate != null)
- {
-
- db.Entry(sUpdate).CurrentValues.SetValues(myModel);
- }
-
- var cUpdate = from c in db.COUNTRIES where c.IDc == myModel.ID select c;
- if (cUpdate != null)
- {
- foreach (var item in cUpdate)
- {
- item.country = myModel.country;
- item.IDc = myModel.ID;
-
-
-
- }
- }
- db.SaveChanges();
This can update the main table "SALES" but table "COUNTRIES" is not updated.