Rachel
Rachel

Reputation: 132548

Can Entity Framework create Objects with default values for Non-Null columns?

I thought I saw something somewhere about being able to generate an object in EF with all the non-null values filled in with generic values.

I tried using context.CreateObject<MyEntity>(), however I am still getting errors about trying to save NULL data to a non-null column.

Was I mistaken in thinking this? Or do I just have the wrong syntax?

Upvotes: 3

Views: 1247

Answers (2)

Jeff Ogata
Jeff Ogata

Reputation: 57783

In the model designer, you can enter a default value on the property sheet for each field.

enter image description here

Upvotes: 3

AD.Net
AD.Net

Reputation: 13399

You can not save null data to a non-nullable column. If CreateObject method gives you that you'll need to change that before trying to save data. Also, watch out for DateTime objects, SQL server has different min value of that than the .NET.

Upvotes: 2

Related Questions