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?

4
  • Thanks for your comment, I'm using EF Database First approach and not Code first. So it is a different question I suppose. Thanks! Commented Jul 4, 2012 at 6:57
  • "As I can see from my Model the Default Value for the property is not set." Is it blank or does it say "<None>". Commented Jul 4, 2012 at 7:05
  • Yes the same for me, in my case adding a default value in the model does not save on the db... any idea how to solve it? Thanks Commented Jul 4, 2012 at 7:07
  • Smt I have tried and does not work for me stackoverflow.com/questions/3137738/… Commented Jul 4, 2012 at 7:11

1 Answer 1

1

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.