I have master table and details table. For example master table is ObjectSet<'MasterObject> and details table is ObjectSet<'DetailObject>. So each MasterObject contains EntityCollection<'DetailObject>.
As I understand I can remove DetailObject from database using following:
EntityCollection<'DetailObject> ec = masterObject.DetailObjects;// as navigation propertyec.Remove(deleting_detail_object);// deleting_detail_object will be removed and marked for deleting.context.SaveChanges();// I have exception
After Remove() the deleting_detail_object.MasterObject (navigation property) is null. It is normal. But context.SaveChanges() give me following exception :
"The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted."
I can delete this DetailObject using context.RemoveObject(), but is it possible to do it using EntityCollection<>?