User2014418618 posted
Hi,
I've this (not unthinkable?) scenario in which when inserting a new object into database, amount of another related object should be changed also (think material - product relationship). Product and material are bound by a foreign-key field in DB.
I used to have this in the code:
instance.Material.AmountAvailable -= instance.MaterialAmountUsed
ExecuteDynamicUpdate(instance.Material)
ExecuteDynamicInsert(instance)
Since then - via exceptions (LINQ creating empty UPDATE clauses causing invalid syntax) and some online reading I have learned that inside Insert/Update partial methods it's only possible to work with object instance directly in question, not others (ExecuteDynamicUpdate
is problematic in code above).
I need to update amount of related object, but I cannot seem to find a way to do it - since it's related to current object I cannot do update via another DataClassesDataContext.
What I'm thinking of right now is implementing this piece of business logic as triggers on database, but I'd prefer to keep it all in .NET code - is there a way?