I'm using EF with DB First. My table looks like this:
CREATE TABLE [dbo].[Person](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](50) NOT NULL,
[dob] [datetime] NOT NULL
CONSTRAINT [PK_Person] PRIMARY KEY CLUSTERED )
GO
ALTER TABLE [dbo].[Person]
ADD CONSTRAINT [DF_Person_dob] DEFAULT ('12.12.3000') FOR [dob]
After using DB First I get the following partial Person class:
using System;
public partial class Person
{
public int id { get; set; }
public string name { get; set; }
public System.DateTime dob { get; set; }
}
The problem I have is that when I want to use the DB generated default value for 'dob' field I get an exception because nulls are not allowed. I'm trying to do this:
using (var db = new NullTestEntities())
{
var person = db.Person.Create();
person.name = "John Doe";
db.Person.Add(person);
db.SaveChanges();
}
I've tried adding
Column(IsDataBaseGenerated=true)
but I can't compile because I get an error:
'System.ComponentModel.DataAnnotations.Schema.ColumnAttribute' does not contain a definition for 'IsDatabaseGenerated'
What do I need to do in order to not define the dob attribute in C# code and let the database generate the default value?