Jul 25 2007

Object Identity in DLinq

Category: DLinqBil@l @ 22:31

I have found out that DLinq internally uses Object Pooling!

Usually, when you retrieve a record from a Database Table, and then retrieve it again, another version is being created for you. This doesn't hold true for C# or VB.NET objects. When  you create an instance of an object, and then request it again, the same instance is brought back (for sure if GC didn't remove it).

With DLinq, when a record is retrieved from the database it is bound or linked to a C#/VB.NET object, its Primary Key is used to store that instance of the object created. So that next time, when you request same Row from the database, a check is made into the store of the "objects pooled" against instance that is mapped to the request Row based on the Primary Key, if the instance is present, then it is retrieved and returned back, else a new instance of the object is created by accessing the database.

Off course, when an update is made to a row, the instance is removed from the pool to maintain integrity of data!

That is really cool!


Comments are closed