views:

192

answers:

2

Can someone give an example to what Ayende is talking about in item #17 on his list of 25 Reasons Not To Write Your Own Object Relational Mapper

Is this something that ADO.NET Entity Framework can do?

+1  A: 

Imagine an AD backed Membership model, which also stores information in SQL. When a user is created you might want to be able to create the user in both AD and in SQL. The life cycle events give you a chance to intercept certain events like Create Update etc..to allow you to do something.

JoshBerke
Any examples of this online? Does NHibernate do part of the work for you wiring up this event? How would this differ from how you would approach the same issue in EF? +1
tyndall
I've never used EF so can't coment on that. Ill see if I can get a sample I can share and will update this once I do
JoshBerke
A: 

NHibernate has an event system, where you get events (actually callbacks) when NHibernate is doing something with your entity. The call backs could be registered on the session or just implemented in the entity using an interface.

There are many examples of the usage of such a callback, and it could be vital for a project. Many people are writing audit logs using these callbacks. Or just updating some properties that are not stored in the database. Ayende probably means that with "fetching data from other locations as well".

I don't know if the entity framework has life cycle callbacks. NHibernate is very very very extensible and you can hook you custom code in to nearly every part. Generally I doubt that entity framework is that extensible.

Stefan Steinegger