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

.net entity-framework

Question

My table has a Date column with the default value or binding set to getutcdate (). This is what I want to utilize in entity framework. I was able to locate the "Default Value" field at the column level when I generated an EDM, however I believe it is for hardcoded values.

Please explain to me how I may utilize the database's default value.

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

Popular Answer

The answer I came up with is to make the entity implement the OnCreated event. I wanted to fill a Guid property that I have. All zeroes were being entered by default (00000-0000-00000-etc). I was able to solve the problem by adding the following to my partial class of the object.

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