Hi all

I'm having some trouble with EF and SQL 2008 default values.

Firstly, I have a column called 'CreatedDate' and the default value in SQL Server is getdate(). If I add a field in SQL server this works fine. I also have a column called Guid and the default value of newid(). this also works fine.

My problem is that these do not see to be honoured in with the EF. I can get round this by setting these properties manually in the code but I'm not sure why this is or if I am supposed to do something different?


using(var ctx = new myEntities())
                Company ct = new Company
                    FullName = "Mynewco",
                    Code = "000110",
                    //Guid = Guid.NewGuid(), 
                    Language = "ENG", 
                    SystemCreatedUser = 1,
                    SystemLastEditDateTime = DateTime.UtcNow  

                    Console.WriteLine("New Customer created with an ID of {0} and a Guid of {1}", ct.ID, ct.Guid);
                catch (Exception ex)

The solution was to set 'StoredGeneratedPattern' to Computed against the property in the EF model.

This question has already been answered. Start a new discussion instead.