I'm using ASP.Net MVC 3 with Code First and SQl Server CE 4. I have a property (with matching database column) called EntryDate. I've set the database to default to a value of GETDATE().

If I manually edit the database by entering a record leaving EntryDate as NULL, the default works and the current date/time is stored. But if I do the same thing by trying SaveChanges() on my context from my controller, with the model object having no value for the EntryDate property, I get the following error:

"The column cannot contain null values. [ Column name = EntryDate,Table name = ActionItems ]"

If I change the database schema to allow for nulls in the EntryDate column, the default rule doesn't fire and I end up with NULL being stored.

Any guidance would be appreciated..

Update: just to be clear, I can easily enough set the property value in the POST action method prior to calling SaveChanges():

```
    [HttpPost]
    public ActionResult Create(ActionItem actionItem)
    {
        if (ModelState.IsValid)
        {
            actionItem.EntryDate = DateTime.Now;
            db.ActionItems.Add(actionItem);
            db.SaveChanges();
            return RedirectToAction("Index");  
        }

```

I would just prefer to set this at the database level. My questions are:

1. Why doesn't it work automatically like the way I'd expect it to?
2. Is there an easier way (i.e. a DataAnnotation)?

I'm new to this, so I think maybe there's some fundamental misunderstanding of what's happening on my part.

Update 2: 

Well I'm stumped at this behaviour. The code above is the only way I can get it to work so I guess I'll stick with that. My most recent try was supplying a [Bind] annotation but it didn't change the result. e.g.

```
[HttpPost]
public ActionResult Create([Bind(exclude = "EntryDate")] ActionItem actionItem)

```

I can run a SQL query against the database itself and it supplies the default value as it should (I've tested with SQLExpress to see if it's a database behaviour but I guess not). But I can't seem to get EF to create the query without including EntryDate = null, or as .minValue if I use datetime instead of datetime?

The funny thing is I'm handling the field the same way as the Id field, which the db supplies itself obviously. I just don't get it.

I guess I have it working but I'd like to understand the mechanism better. If anyone can shed some light on this that'd be great..

Thanks