Tag Archives: EF

Duplicate Key Exception

Entity Framework throws exceptions from the DbContext’s SaveChanges method if there is a constraint violation in the database. If you have a property marked as invariant w.r.t. concurrency, that too will raise an exception at this point (a DbUpdateConcurrencyException Exception. … Continue reading

Posted in EF | Tagged , , , | Leave a comment

Architecture : Entity Framework

I’ve had an extensive opportunity to play with entity framework. Here are my few thoughts. Code first does work reasonably well if you are starting from scratch, but managing the release of vital enterprise applications, which require care around the DB become … Continue reading

Posted in EF | Tagged , , | Leave a comment

Entity Framework and POCOs

So I finally got around to trying Entity Framework with POCOs, where the domain model objects were hand coded and there was an aleady existing database. The process was initially simple: run the tool that creates a model diagram of … Continue reading

Posted in EF | Tagged , , | Leave a comment

Sum and Count in EF

It bugs me that I need to play around with casting in linq expressions just to make aggregate functions safe. For example: decimal? total = storeDb.Carts .Where(cart => cart.CartId == ShoppingCartId) .Select(c => (decimal ?)c.Count * c.Album.Price) .Sum(); See that … Continue reading

Posted in EF | Tagged , , , | Leave a comment