I have an SQL Server stored procedure that ressembles this:
我有一个SQL Server存储过程,它重新解决这个问题:
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)?
当我在EF中执行函数导入/获取列信息时,列IsGetBarCol2EqualToThree的推断类型是Nullable
The SQL Server version is 2005, I'm using Visual Studio 2010SP1 with EF 4, project is compiled against .net 4.0.
SQL Server版本是2005,我使用Visual Studio 2010SP1和EF 4,项目是针对.net 4.0编译的。
3 个解决方案
#1
10
Make this modification: isnull([dbo].[GetBar](T.Col2), 0)
进行此修改:isnull([dbo]。[GetBar](T.Col2),0)
#2
1
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.
您可以创建复杂类型,然后修改生成的字段的Nullable属性。如果您不想更改sp,可能会很有用。
step by step:
一步步:
- open your edmx
- 打开你的edmx
- open model browser (View->Other Windows->Entity Data Model Browser)
- 打开模型浏览器(查看 - >其他Windows->实体数据模型浏览器)
- navigate to the field in your generated complex type (*.emdx->Model->Complex Types->your type->field)
- 导航到生成的复杂类型中的字段(* .emdx-> Model-> Complex Types-> your type-> field)
- open properties window (press F4)
- 打开属性窗口(按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.
- 属性中应该有Nullable。您可以在此处进行更改,并且不会在下一次模型更新时覆盖它,但如果重新创建复杂类型,则会丢失调整。
Alternatively you can open edmx as xml and find the same property.
或者,您可以将edmx作为xml打开并找到相同的属性。
<ComplexType Name="...">
<Property Type="Int32" Name="..." Nullable="true" />
ps: I tested it in VS2012, EF 5
ps:我在VS2012,EF 5中进行了测试
#3
0
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 .
1- alter procedure is isnull(“your expression”,0)然后从数据库更新模型并刷新。
2- you can open the class model and change it manually but any update on the model again , you will lost the change .
2-您可以打开类模型并手动更改它,但是再次对模型进行任何更新,您将丢失更改。
So my opinion is the first solution is the best.
所以我的观点是第一个解决方案是最好的。
#1
10
Make this modification: isnull([dbo].[GetBar](T.Col2), 0)
进行此修改:isnull([dbo]。[GetBar](T.Col2),0)
#2
1
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.
您可以创建复杂类型,然后修改生成的字段的Nullable属性。如果您不想更改sp,可能会很有用。
step by step:
一步步:
- open your edmx
- 打开你的edmx
- open model browser (View->Other Windows->Entity Data Model Browser)
- 打开模型浏览器(查看 - >其他Windows->实体数据模型浏览器)
- navigate to the field in your generated complex type (*.emdx->Model->Complex Types->your type->field)
- 导航到生成的复杂类型中的字段(* .emdx-> Model-> Complex Types-> your type-> field)
- open properties window (press F4)
- 打开属性窗口(按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.
- 属性中应该有Nullable。您可以在此处进行更改,并且不会在下一次模型更新时覆盖它,但如果重新创建复杂类型,则会丢失调整。
Alternatively you can open edmx as xml and find the same property.
或者,您可以将edmx作为xml打开并找到相同的属性。
<ComplexType Name="...">
<Property Type="Int32" Name="..." Nullable="true" />
ps: I tested it in VS2012, EF 5
ps:我在VS2012,EF 5中进行了测试
#3
0
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 .
1- alter procedure is isnull(“your expression”,0)然后从数据库更新模型并刷新。
2- you can open the class model and change it manually but any update on the model again , you will lost the change .
2-您可以打开类模型并手动更改它,但是再次对模型进行任何更新,您将丢失更改。
So my opinion is the first solution is the best.
所以我的观点是第一个解决方案是最好的。