I have an SQL Server stored procedure that ressembles this:
CREATE PROCEDURE [jp].[GetFoo]
@Guid UNIQUEIDENTIFIER
AS
SELECT
CONVERT(BIT, (CASE WHEN [dbo].[GetBar](T.Col2) = 3 THEN 1 ELSE 0 END)) IsGetBarCol2EqualToThree
FROM
[dbo].[MyTable] T
WHERE
T.Col1 = @Guid
When I do Function Import / Get Column Information in EF, the inferred type of the column IsGetBarCol2EqualToThree is Nullable<bool>
. But there is no way this field is going to be null, so I'd like it to be just bool
. Is there a way to do this that would be persistent upon updating (ie that does not rely on modifying any generated code)?
The SQL Server version is 2005, I'm using Visual Studio 2010SP1 with EF 4, project is compiled against .net 4.0.
Make this modification: isnull([dbo].[GetBar](T.Col2), 0)
You can create complex type and then modify the Nullable property of the generated field.
Can be useful if you don't want to change your sp.
step by step:
- open your edmx
- open model browser (View->Other Windows->Entity Data Model Browser)
- navigate to the field in your generated complex type (*.emdx->Model->Complex Types->your type->field)
- open properties window (press F4)
- among properties there should be Nullable. You can change it here and it will not be overwritten on the next model update, but if you recreate the complex type you will loose your tweak.
Alternatively you can open edmx as xml and find the same property.
<ComplexType Name="...">
<Property Type="Int32" Name="..." Nullable="true" />
ps: I tested it in VS2012, EF 5
You have to ways to fix this issue
1- alter procedure to be isnull ("your expression", 0) then update your model from database and refresh .
2- you can open the class model and change it manually but any update on the model again , you will lost the change .
So my opinion is the first solution is the best.