In Entity Framework, how can I utilize the default column value from a DataBase?

.net entity-framework

Question

I have a Date column in table which has default value or binding as getutcdate(). I want to use this in entity framework.On generating EDM I was able to find "Default Value " property at column level but I think it is for hardcoded value.

Please let me know how can I use default value specified in database.

1
41
5/24/2016 1:06:23 PM

Popular Answer

Implementing the OnCreated event for the entity is the solution I have found. I had a Guid property that I wanted to be populated. By default it was being populated with all zeros (00000-0000-00000-etc). By adding the following to my partial class of the entity I was able to deal with the issue.

partial void OnCreated()
{
    Guid = Guid.NewGuid();
}
9
10/28/2010 10:20:36 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow