This project is read-only.
  • OneToOne : In a One – to – One scenario, both objects have to know about themselves (In OOP, but in relational world, they are joined by primary to foreign key). For example Table 1 will have a foreign key to table 2, and table 2 may or may not have a foreign key to table one. Even if the foreign key relationship is not enforced at the database level, all you need is to configure it in the object layer, that’s another elegant thing about the framework. It is not always required to have the relationship in both directions, but if you want both object to see each other in object world, then you need to do either of the following :
  1. Create keys that maps to each other.
  2. Create Foreign Key to one table, and use the attribute OneToOne(typeof(Customer), RelationColumn ="AddressId", IsImported = true) to import the address Id from the Customer object. Let me put more light into all of this:

A Customer object (In our context) have only one Address. So in this sample, the AddressId is configured in the Customer table, even though we also configured the CustomerId in the Address table, we are not using that to fetch the customer that is related to this Address, we are telling Framework with the attribute above, that the addressId resides in Customer table, and that it should get it from there. We can as well use the following since we configured the CustomerId in the Address table, OneToOne(typeof(Customer), RelationColumn = "CustomerId") (for Address) and this for customer OneToOne(typeof(Customer), RelationColumn = "AddressId") . But if we don’t want to achieve this in two way form, we will use the import = true, in one of the related classes, and we will specify the fetch column, in the other related class.

Last edited Feb 23, 2010 at 2:37 PM by ahmedsalako, version 1


No comments yet.