I’m using Entity Framework 4.1 Code First Fluent API.
The problem. I have an Entity Framework model being used in the business layer called Patient, it has a collection of dependent entities called Responses, when a response needs to be deleted I simply remove it from the collection and expect that it’ll get deleted from the database. It doesn’t. Read the rest of this entry »


Need to perform validation on a model’s property based on some other state of the model? Here’s a way to achieve it using the IValidatableObject interface and data annotations.

In our example project we want to validate the state field is a valid Australian state if the country field is “Australia”.

Conditional validation of state field

Read the rest of this entry »


There’s plenty of examples on how to find duplicates using LINQ’s GroupBy method, but usually they use a projection to return a new object, like this:

_filteredSubmissions = (from s in _filteredSubmissions
                        group s by s.Email
                        into g
                        where g.Count() > 1
                        select new { Emails = g.Key, DuplicateCount = g.Count() }

Read the rest of this entry »