GibboK
GibboK

Reputation: 73898

Default Values using Entity Framework 4

I have a table with a column as:

nvarchar(256) NoteInternal NOT NULL DF_ReOptions_NoteInternal DEFAULT ''

I'm using Database First approach and T4 for generating the POCOs. As I can see from my Model the Default Value for the property is not set.

A good explanation of why at this page Entity Framework 4 and Default Values

When I'm setting manually the Default Value in the model I can see the default value in the POCO generated, but at the moment of saving on the database the default value is not being inserted and I receive an error in VS and not data in the DB.

My question, How can i insert default value using EF?

May I use DataAnnotation or System.ComponentModel namespace to solve the problem?

Upvotes: 4

Views: 2630

Answers (1)

GibboK
GibboK

Reputation: 73898

here some of the possible solution for my case:

01 - Implementing some BL logic on DbContext overridding SaveChanges()

EF 4.1 - How to add a default on insertion for datetime column I chose this option

02 - Adding the default value in the View (using MVC)

Upvotes: 1

Related Questions