I have a question. How can I delete one field and all other one to many relations?
Field has
- List<Years>
Years has
- List<Crop>
Crop has
- List<Pesticide>
- List<Fertilizer>
if i use
db.Fields.Remove(field);
it will only delete the field not all related records
How can remove all years if remove a field or if i remove a year all crops will be removed
UPDATE:
I have tried:
modelBuilder.Entity<Entity.Field>()
.HasOptional(c => c.Years)
.WithMany();
Query IQueryable<Entity.Field> query = ctx.Set<Entity.Field>()
.Include(c => c.Years);
var list = query.ToList();
but I get this error:
Error: MetadataException: The declared type of navigation property FieldManager.Context.Field.Years is not compatible with the result of the specified navigation