Employee emp = new Employee();
var results = emp.Select(emp.From().Where(x=>x.Name == "Ali"));
I know those are not hard to do things, if the POCO’s have Db connections on their instance like ServiceStack Services.
What is the best way of sharing Db in POCO classes? (Injection or something else ? )
It’s no longer a POCO if it contains a DB connection, you’ve also just limited the reusability of the model to DB persistence, you now have to be careful that you didn’t break serialization and have to make sure your disposing resources properly.
Overall I think it’s a bad idea for models to contain managed resources and would recommend against it.
Also when you’re in a Service you don’t need to open a new DB Connection, you can just access it with:
Db.Insert(emp);
ServiceStack takes care of opening the new connection on first access and disposing after Service has been executed.
Your other dependencies can inherit RepositoryBase which provides a similar UX for accessing the DB connection outside of your Services.
You can use Update/Insert filters on OrmLite to fire callbacks when each model gets saved. You can also call your own custom Insert extension method off IDbConnection which executes custom logic before calling OrmLite. Anything but couple your models to a DB Connection.
Thank you Rob and mythz,
But this is not fits my need.
Because I need, both before and after methods. This only gives me before event.
And also there is no before/after delete methods.