I think that Entity Framework does not have a good support for stored procedure. I would like to have a better stored procedure mapper.
我认为实体框架对存储过程没有很好的支持。我想有一个更好的存储过程映射器。
The problem is : my stored procedure have an IF
statement. Inside the IF
, I'm doing the SELECT
. When my code does not get inside the IF
, the stored procedure does not select data. When I don't select data, Entity Framework's autogenerated code crashes.
问题是:我的存储过程有一个IF语句。在IF中,我正在做SELECT。当我的代码没有进入IF时,存储过程不会选择数据。当我不选择数据时,Entity Framework的自动生成代码崩溃。
1 个解决方案
#1
3
The problem is : My stored procedure have a IF statement. Inside the IF i'm doing the SELECT. When my code does not get inside the IF the stored proc does not select data. When I don't select data the entity framework autogenerated code crashes.
问题是:我的存储过程有一个IF语句。在IF里面我正在做SELECT。当我的代码没有进入IF时,存储的proc不会选择数据。当我不选择数据时,实体框架自动生成的代码崩溃。
EF crashes because it is expecting a resultset of type x (whatever is your type), but it gets nothing if your stored procedure does not pass your if condition. The way to solve this is easy: Return an empty resultset which has the exact same number of columns from your stored procedure when the condition does not pass. Every branch of your stored procedure should return the same resultset or return an error but then you need to handle the error on your application side.
EF崩溃是因为它期望x类型的结果集(无论你的类型是什么),但是如果你的存储过程没有通过你的if条件,它就什么都没有。解决这个问题的方法很简单:当条件未通过时,返回一个空的结果集,该结果集具有与存储过程完全相同的列数。存储过程的每个分支都应返回相同的结果集或返回错误,但您需要在应用程序端处理错误。
#1
3
The problem is : My stored procedure have a IF statement. Inside the IF i'm doing the SELECT. When my code does not get inside the IF the stored proc does not select data. When I don't select data the entity framework autogenerated code crashes.
问题是:我的存储过程有一个IF语句。在IF里面我正在做SELECT。当我的代码没有进入IF时,存储的proc不会选择数据。当我不选择数据时,实体框架自动生成的代码崩溃。
EF crashes because it is expecting a resultset of type x (whatever is your type), but it gets nothing if your stored procedure does not pass your if condition. The way to solve this is easy: Return an empty resultset which has the exact same number of columns from your stored procedure when the condition does not pass. Every branch of your stored procedure should return the same resultset or return an error but then you need to handle the error on your application side.
EF崩溃是因为它期望x类型的结果集(无论你的类型是什么),但是如果你的存储过程没有通过你的if条件,它就什么都没有。解决这个问题的方法很简单:当条件未通过时,返回一个空的结果集,该结果集具有与存储过程完全相同的列数。存储过程的每个分支都应返回相同的结果集或返回错误,但您需要在应用程序端处理错误。