var main = (from d in db.Discounts where d.Id == discount.Id && d.UserId == userId select d).FirstOrDefault();
main.Address = "new address";
main.TermsStocks.Clear(); // I need clear collection and add new object.
foreach (var termsStock in terms)
{
main.TermsStocks.Add(new TermsStock() { Id = Guid.NewGuid(), MainId = main.Id, Title = termsStock.Title });
}
db.SaveChanges();
と私はエラーがあります:コレクションを削除する方法は?
The operation failed. Unable to change the link because one or more properties of the foreign key values do not allow NULL. If you change the connection property of the respective foreign key set to NULL. If the foreign key value does not support NULL, must be defined a new relationship, the foreign key property should be set to another value other than NULL, or to remove unbound object.
どのようにコレクション全体を削除し、新しいものを保存するには?
[Entity Framework 4エンティティコレクションからのオブジェクトの削除]の可能な複製(http://stackoverflow.com/questions/4922228/entity-framework-4-delete-object-from-entity-collection) –