1

We have a database view which includes a UNION query. The first SELECT statement in the query pulls a not null DateTime field. The second SELECT statement deliberately has a NULL in place of this field.

When we asked EF to "Update model from database" the object it created has a standard DateTime to represent this field, rather than a Nullable. So every time it selects records from the view which have NULLS for this field, it falls over.

Is there any way, besides making the field in the original table nullable, that we can get EF to treat this as a nullable field?

Bob Tway
  • 9,301
  • 17
  • 80
  • 162

2 Answers2

1

Yes, you can do that.

First, change to false (Default is True) the option Update Property Facets in the ConceptualEntityModel.

ConceptualEntityModel

Then, go to the EntityType, select the property you want to have nullable and set the attribute Nullable as True

Nullable Field

After this two changes, when you Update your model from database the property will remain as Nullable

Hope this helps

CrApHeR
  • 2,595
  • 4
  • 25
  • 40
-1

I found this to help: wrap your field in ISNULL() on the DB view to force the nullable

Entity Framework and SQL Server View

Community
  • 1
  • 1
Charles D.
  • 87
  • 3