title: Old Nulls and Entity Framework
body: <p>I'm moving a sloppy old Access DB to a crisp new SQL Server database and using EF Code First to design and manage the DB. </p>
  
  <p>I started it out locking down all the stuff that I did not want to be nulls, but then I got to the sloppy old data and found that there were nulls in the old data in many places. I can't recreate the old data from history, so I guess I need to allow nulls in the new DB. </p>
  
  <p>...but I definitely want to prevent any more sloppy data entering the db. If I put a [Required] attribute it will block new bad data but it will also create the db column as NOT NULL and therefore prevent the migration of the old data. </p>
  
  <p>So how do I lock down the DB to prevent new nulls coming in? Of course I can secure the UI to prevent it, but I'm kind of paranoid and would love to lock the DB down to not allow new rows having nulls. One way to do this is to go behind EF and write a trigger to throw an exception if the Inserted row contains nulls in the columns I want to protect. That will work but I was wondering if there is some way to do it directly in EF and have less code to maintain.</p>