views:

21

answers:

1

Hi,

Does does class/object models have a out-of-the-box equivalent to a database foreign key constraint? Assume the language is C# please.

That is say Class A has a field that references Class B and vica-versa. If I have Object A & B (instantiated from these classes) what happens if I delete Object B? Does it auto-delete or throw a constraint issue if it still exists in Object A as a reference?

That is, for this scenario is there a way to ensure when a Object A is delete that either (a) object B is delete like a cascade delete, or (b) a constraint exception is thrown as the expectation is that the reference in Class B should be non-null?

+1  A: 

Per se, no. Foreign key is property of some DBMSs. But you can simulate this in a lot of ways in an object oriented arquitecture.

eKek0
you mean just through putting coding checks in appropriately? i.e. there is no specific C# directive/class/syntax/etc that directly assists here is there?
Greg