Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell Entity Framework that a column in a view is nullable?

I have a view which has an Int column which is nullable (let's call it StackOverflowCount). When generating an EF model from the database, the EF designer does not recognise it as nullable and creates the column as an Int.

The issue I have is that on the EF designer I have set the column to Nullable and the following error then kills the compilation;

Error 3031: Problem in mapping fragments starting at line 2327:
Non-nullable column MyView.StackOverflowCount in table MyView
is mapped to a nullable entity property.

I can get round this by opening the .edmx file in XML mode and manually editing the SQL column definition, but there is no way to do this using the designer and it gets overwritten the next time I refresh from the model from the DB.

Is this 'by design' or an example of something that slipped through into EF 4.0? I'm using .Net 4.0 with EF 4.0 under VS 2010.

like image 601
Ryan O'Neill Avatar asked Nov 14 '22 10:11

Ryan O'Neill


1 Answers

EF has a lot of functionality that is not available in the designer.

This is not so much "by design", but probably that they ran out of time.

There are several improvements in EF in VS2010, see http://msdn.microsoft.com/en-us/data/ee720194.aspx

like image 85
Shiraz Bhaiji Avatar answered May 13 '23 20:05

Shiraz Bhaiji