实体框架无法处理简单的表变量?

O.O*_*O.O 13 c# entity-framework-4

  • 存储过程的最后一行: select * from @t
  • 更新了模型,它找到了存储过程
  • 试图使用向导导入一个新功能,它说没有找到任何列.

真的吗?有人告诉我它的谎言.

create procedure WorkIt
as
set nocount on

create table #pivot
(
    Name varchar(30),
    Value decimal,
    Grade varchar(2)
)

insert into #pivot
select 'Repeating Pct', 1, 'K'
union all
select 'Repeating Pct', 2, '1'
union all
select 'Repeating Pct', 3, '2'
union all
select 'Repeating Pct', 4, '3'
union all
select 'Repeating Pct', 5, '4'
union all
select 'Repeating Pct', 6, '5'
union all
select 'Repeating Pct', 7, '6'  
union all
select 'Repeating Pct', 8, '7'
union all
select 'Repeating Pct', 9, '8'
union all
select 'Repeating Pct', 10, '9'
union all
select 'Repeating Pct', 11, '10'
union all
select 'Repeating Pct', 12, '11'
union all
select 'Repeating Pct', 13, '12'
declare @t table
(
    name varchar(30),
    K decimal (15,5) ,
    [1] decimal (15,5),
    [10] decimal (15,5),
    [11] decimal (15,5),
    [12] decimal (15,5),
    [2] decimal (15,5),
    [3] decimal (15,5),
    [4] decimal (15,5),
    [5] decimal (15,5),
    [6] decimal (15,5),
    [7] decimal (15,5),
    [8] decimal (15,5),
    [9] decimal (15,5)
)
insert into @t
exec dbo.CrossTabWithoutSumWithOrderBy #pivot, 'Name', null, 'Grade', 'Value', 
    -- sort repeating pct to bottom
    'case name when ''Repeating Pct'' then 999 else 0 end'

drop table #pivot
select * from @t
Run Code Online (Sandbox Code Playgroud)

结果

name    K   1   10  11  12  2   3   4   5   6   7   8   9
Repeating Pct   2.00000 11.00000    12.00000    13.00000    3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 10.00000    1.00000
Run Code Online (Sandbox Code Playgroud)

Lad*_*nka 26

当实体框架尝试从它调用的存储过程中检索列时,SET FMTONLY ON然后执行存储过程.如果FMTONLYON执行只返回的元数据,它不具有一定的先进性建设在存储过程中的工作-例如动态SQL,临时表也表变量.

你有三个选择:

  • 如在另一个答案中所述,SET FMTONLY OFF在存储过程开始时添加.这将导致您的存储过程真正执行,因此请确保它只读取数据 - 每次尝试检索列时都会执行任何插入,更新或删除!
  • 手动定义复杂类型
  • 修改存储过程以不使用任何此功能

  • 这不是EF的问题.EF必须调用`SET FMTONLY ON`以确保存储过程意外地不会触发任何数据修改,一旦这被称为SQL服务器行为不同 - 即SQL服务器"功能". (2认同)