Entity Framework can't handle a simple table variable?

前端 未结 2 1282
眼角桃花
眼角桃花 2020-12-03 03:58
  • The last line in the stored procedure: select * from @t
  • Updated model and it found the stored procedure
  • Tried to import a new function u
相关标签:
2条回答
  • 2020-12-03 04:06

    I had a similar issue with edmx (in my case it was if else statement), there was a work around. Before updating edmx, declare some variables of your return type, select them. Update model, then modify your stored procedure with your real code. I.e:

    declare @name varchar(30),
        @K decimal (15,5) ,
        @x1 decimal (15,5),
        @x10 decimal (15,5),
        @x11 decimal (15,5),
        @x12 decimal (15,5),
       @x2 decimal (15,5),
        @x3 decimal (15,5),
        @x4 decimal (15,5),
        @x5 decimal (15,5),
       @x6 decimal (15,5),
        @x7 decimal (15,5),
        @x8 decimal (15,5),
        @x9 decimal (15,5)
    
    Select @name, @k, @x1, @x10, @x11, @x12, @x2, @x3, @x4, @x5, @x6, @x7, @x8, @x9
    

    Of course, you should keep this dummy code commented in your stored procedure and write a comment in it. so that when anyone updates it with edmx should uncomment this dummy code and comment the real code.

    0 讨论(0)
  • 2020-12-03 04:19

    When entity framework tries to retrieve columns from stored procedure it calls SET FMTONLY ON and after that executes the stored procedure. When FMTONLY is ON execution returns only metadata and it doesn't work with some advanced construction in stored procedures - for example dynamic SQL, temporary tables and also table variables.

    You have three choices:

    • As described in another answer add SET FMTONLY OFF at beginning of your stored procedure. This will cause your stored procedure to really execute so make sure it only reads data - any insert, update or delete will be executed each time you try to retrieve columns!
    • Manually define complex type
    • Modify your stored procedure to not use any of this features
    0 讨论(0)
提交回复
热议问题