c# - Why does changing the name of an Entity change program behavior? -
i have code first ef model setup, , experimenting adding records using both entities , id values. not shown here, "above" code setup , added context other entities (eg, ucarparents, ualice, etc)
then hit block of code. note time call context.savechanges() 1 @ end of block.
var uba = new list<userbooleanattribute> { new userbooleanattribute {userattribute= ucarparents, user = ualice}, new userbooleanattribute {userattribute = ucarteens, user = ubob}, new userbooleanattribute {userattributeid = 3, userid = 1}, new userbooleanattribute {userattributeid = 4, userid = 2} }; uba.foreach(ua => context.userbooleanattributes.add(ua)); context.savechanges();
savechanges works, assertions pass. pointed out me name of userbooleanattribute should projectbooleanattribute. changed , fk exception on savechanges.
somewhat perplexed, put savechanges() above block , started working again. suspicion problem adding new userbooleanattributes using id's somehow involved. indeed, if replaced 2 lines passing in userattribute , user instead of id's, started working without savechanges.
but got me wondering why working in first place.
so started more testing renaming booleanattribute xxxbooleanattribute works. vvvbooleanattribute, uuubooleanattribute not work.
this behavior rather strange least. i'm guessing, looks ef (and sql server) might updating tables in order based upon how class named.
Comments
Post a Comment