Why can't Entity Framework see my Stored Procedure's column information?

后端 未结 10 1331
终归单人心
终归单人心 2020-12-02 14:54

I have the following stored procedure and when I attempt to Function Import it says my Stored Procedure returns no columns. What am I missing? Any Suggestions?

The

10条回答
  •  醉话见心
    2020-12-02 14:59

    This is the only correct answer and can be found from here

    https://stackoverflow.com/a/27960583/511273

    Basically, EF knows that it's always going to return the number of rows or -1 if NO COUNT is on, or anything returned from the SQL stored procedure that's called by return . For that reason, no matter what stored procedure you import, the type will always be nullable. You can only return an integer from an SQL stored procedure. So, EF gives you a way to edit your function. I would imagine that if you edited it manually you would overwrite it on refresh, but I can't confirm that. Either way, this is the facility provided by EF to deal with this issue.

    Click on your .emdx file. It has to be the one you selected in the Solution Explorer. Select Model Browser (Right beside Solution Explorer tab, above Properties). Expand Function Imports, locate your stored procedure, right click, click Edit. Select your variable type. It can either be a primitive type or you can click Get Complex Type. Click Get Column Information. I have confirmed this survives a model refresh.

    Why can you only return an integer from a stored procedure? I don't really know, but this return definition explains that you can only return an integer: https://docs.microsoft.com/en-us/sql/t-sql/language-elements/return-transact-sql?view=sql-server-ver15

提交回复
热议问题