我认为 Entity Framework 对存储过程的支持不是很好。我想要一个更好的存储过程映射器。
问题是:我的存储过程有一个 IF
语句。在 IF
中,我正在执行 SELECT
。当我的代码没有进入 IF
时,存储过程不会选择数据。当我不选择数据时,Entity Framework 的自动生成代码会崩溃。
最佳答案
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.
EF 崩溃是因为它需要一个类型为 x 的结果集(无论您的类型是什么),但是如果您的存储过程没有通过您的 if 条件,它什么也得不到。解决这个问题的方法很简单:当条件未通过时,返回一个空结果集,该结果集的列数与存储过程中的列数完全相同。存储过程的每个分支都应返回相同的结果集或返回错误,但随后您需要在应用程序端处理错误。
关于c# - 有没有办法在没有 Entity Framework 的情况下从 C# 中的 SQL Server 映射存储过程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42015045/