Question

I'm trying to replicate many of the practices we use with NHibernate in EF CTP4.

Currently we have a generic repository interface (CTP4 actually makes this quite easy with DbContext.Set).

We are passing in the context and using StructureMap to scope it per HttpRequest.

With NHibernate we pass in ISession (again created using StructureMap) but use an ActionFilter (UnitOfWork) to commit the transaction at the end of the request.

Do we have equivalent transactions in EF CTP4? If not, should I use the same filter to call context.SaveChanges() or just do this inside the repository.

On a side note, what's the easiest way of testing to see whether an entity is new or not. With NH we have the luxury of just calling ISession.SaveOrUpdate. Note that all my entities use a Guid identifier. Perhaps a check for default(Guid)?

Thanks.

Was it helpful?

Solution

I know this is a late answer that you will have figured out by now but i guess its useful for people searching. Rob conery has a great post on using actionfilter and Ef to create transactions per request scope.

Rob C Article

Oh and yes I would create an UpdateInsert() method on a generic repository that test for default(Guid).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top