3

我们创建了一个使用实体框架连接数据库的 WPF 应用程序。在数据库中有几个我想执行的存储过程。我已经将存储过程作为函数导入到 EF 中,一切看起来都很好,但不是。如果我执行存储过程,数据库中不会发生任何事情。如果我在 SQL Server Management Studio 中使用相同的数据执行存储过程,则某些行正在按预期处理。情况并非总是如此。当我禁用 CONCAT_NULL_YIELDS_NULL、QUOTED_IDENTIFIER、ANSI_NULL_DFLT_ON、ANSI_PADDING、ANSI_WARNINGS 和 ANSI_NULLS 时,它才开始在 SQL Server Management Studio 中工作。我怎样才能让它在应用程序本身中工作?

圭多

4

2 回答 2

1

通过使用解决了这个问题:

Context.ExecuteStoreCommand(@"
   SET CONCAT_NULL_YIELDS_NULL OFF
   SET QUOTED_IDENTIFIER OFF
   SET ANSI_NULL_DFLT_ON OFF
   SET ANSI_PADDING OFF
   SET ANSI_WARNINGS OFF
   SET ANSI_NULLS OFF

   exec sp params
")
于 2013-06-30T12:03:38.810 回答
0

If you use Entity Framework 6 then we can set Ansi warning off but its scope is transaction , where ever you used sp or savechanges method you need to have this code and after that you need to dispose that transaction

DbContextTransaction _transactionContext;
_transactionContext = _Context.Database.BeginTransaction();
_Context.Database.ExecuteSqlCommand("SET ANSI_WARNINGS OFF");
//Start:Below code is project specific
_Context.Entry(SBSB_SUBSC).State = entityState;
status = status + _Context.SaveChanges();
//End
if (_transactionContext != null)
    _transactionContext.Dispose();
于 2016-09-14T11:59:34.337 回答