How do I tell Entity Framework Function Import that a column returned by a stored procedure is not nullable?

前端 未结 3 1707
小鲜肉
小鲜肉 2021-01-01 18:43

I have an SQL Server stored procedure that ressembles this:

CREATE PROCEDURE [jp].[GetFoo]
    @Guid UNIQUEIDENTIFIER
AS

SELECT
    CONVERT(BIT, (CASE WHEN          


        
相关标签:
3条回答
  • 2021-01-01 19:06

    Make this modification: isnull([dbo].[GetBar](T.Col2), 0)

    0 讨论(0)
  • 2021-01-01 19:06

    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.

    0 讨论(0)
  • 2021-01-01 19:12

    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

    0 讨论(0)
提交回复
热议问题