Friday, January 9, 2015

How to Fix the Entity Framework error "Problem in mapping fragments"


In this article we see How to Fix the Entity Framework error "Problem in mapping fragments" : "Non-nullable column  is mapped to a nullable entity property" :


How to Fix the Entity Framework error "Problem in mapping fragments"




 How to Fix the Entity Framework error "Problem in mapping fragments"


This Entity Framework error is originated when your Data Model contains an Entity with a nullable property , while at the Data Store, the mapped column has been defined as non-nullable.
Let's see the Error Message : some "Non-nullable column" has been mapped to a  "nullable entity property" , therefore let's locate at the Model (not at the "Store") that property : in our case, is the property "name" :

How to Fix the Entity Framework error "Problem in mapping fragments"  1


Now we open the "Details" window to take a look at the property :
How to Fix the Entity Framework error "Problem in mapping fragments"  2

We find there that the Entity Model property mapped to the non-nullable column , has not set the "Nullable" field.

So set it in the way that conforms to the Store's column definition:
How to Fix the Entity Framework error "Problem in mapping fragments"  3


After that, you can "validate" the Entity Data Model by right clicking on the property :

How to Fix the Entity Framework error "Problem in mapping fragments"  4

In this case, because there is only one property wrongly mapped, the Data Model is validated with no errors:
How to Fix the Entity Framework error "Problem in mapping fragments"  5



By Carmel Shvartzman

עריכה: כרמל שוורצמן