Entity framework unable to delete object with relationship -


i have 2 tables 1:1 relation. created them using model first approach of entity framework. want delete record, can't delete 1 table , not other, when try following exception:

'a relationship being added or deleted associationset 'fk_lm_ab_profile_lm_profile_master'. cardinality constraints, corresponding 'lm_ab_profile' must added or deleted.'

i have profile table relationship abprofile, want delete profile , abprofile. both use profile_id pk, , abprofile has profile_id fk

my code:

        //get old profile see if 1 exists             var oldprofile = context.lm_profile_master.firstordefault(p => p.profile_id.equals(profileid));              lm_ab_profile ab = new lm_ab_profile();              //check see if user doesn't exist             if (oldprofile != null)             {                      //try , specify relationship between profile , abprofile using profileid                     oldprofile.lm_ab_profilereference.entitykey = new system.data.entitykey("luminusentities.lm_ab_profile", "profile_id", profileid);                           //remove found object database , persist changes                        context.deleteobject(oldprofile);                     context.savechanges();               } 

how can specify 2 tables related when delete record one, other record delete also...i set tables cascading function on model.

the situation described constraint between tables. try affect consistency.

look @ delete object , of related entities in entity framework , define on delete cascade


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -