I’m trying to remove object from my context using the “remove” method.
But i get an UpdateException saying :
ORA-01407: cannot update (“NAMUR_TEST_ALERTE”.”TX_HST_TRACE_DATA”.”TRD_ID_INFO_TRACE”) to NULL
where TRD_ID_INFO_TRACE is my foreign key.
Here is my query linq :
List<Trace> query = (from t in Repository.DataContext.Trace
.Include("Datas")
select t).ToList<Trace>();
If i suppress the include instruction. It works fine.
But i can’t because, the purpose of this is to retreive datas, store them using serialization and finally, delete them from database.
How can i make the remove keeping my include ?
thanks in advance !
The problem is that your model is not configured for cascade delete but your database probably is. If model is not configured for cascade delete removing principal entity will force FK in dependent entities to be set to null and this change will be send to database as update.
One way to solve this is configuring your relations in EDMX or ftuent API (it should be default for mapping by conventions) to cascade deletion. Other way is to remove in code all related data instances prior to removing trace instance.