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?

Community
  • 1
  • 1
GibboK
  • 71,848
  • 143
  • 435
  • 658
  • Thanks for your comment, I'm using EF Database First approach and not Code first. So it is a different question I suppose. Thanks! – GibboK Jul 04 '12 at 06:57
  • "As I can see from my Model the Default Value for the property is not set." Is it blank or does it say "". – Ryan Amies Jul 04 '12 at 07: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 – GibboK Jul 04 '12 at 07:07
  • Smt I have tried and does not work for me http://stackoverflow.com/questions/3137738/how-to-set-default-value-for-pocos-in-ef-cf – GibboK Jul 04 '12 at 07:11

1 Answers1

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)

Community
  • 1
  • 1
GibboK
  • 71,848
  • 143
  • 435
  • 658