简体   繁体   English

在实体框架核心中调用存储过程,参数不以@或#开头

[英]Calling Stored Procedure in Entity Framework Core with parameters not start with @ or #

I'm writing a data layer based on ef-core 2.2, which need to be compatible with SqlServer and Oracle. 我正在编写一个基于ef-core 2.2的数据层,它需要与SqlServer和Oracle兼容。

When calling a SP with complex data format (like binary) or output parameters, a SqlParameter instance need to be created. 调用具有复杂数据格式(如二进制)或输出参数的SP时,需要创建SqlParameter实例。 The name of the parameter is started with @ or #, based on the type of the database chosen. 根据所选数据库的类型,参数名称以@或#开头。

How to avoid use the prefix @ or #, for database compatibility? 如何避免使用前缀@或#,以实现数据库兼容性?

Thanks. 谢谢。

Unfortunately in sql you have to use @ but in oracle you can remove it. 不幸的是在sql中你必须使用@但在oracle中你可以删除它。 Working with parameter placeholders The syntax for parameter placeholders depends on the data source. 使用参数占位符参数占位符的语法取决于数据源。 The .NET Framework data providers handle naming and specifying parameters and parameter placeholders differently. .NET Framework数据提供程序以不同方式处理命名和指定参数和参数占位符。 This syntax is customized to a specific data source, as described in the following table. 此语法是针对特定数据源自定义的,如下表所述。

System.Data.SqlClient   Uses named parameters in the format @parametername.

System.Data.OleDb   Uses positional parameter markers indicated by a question mark (?).

System.Data.Odbc    Uses positional parameter markers indicated by a question mark (?).

System.Data.OracleClient    Uses named parameters in the format :parmname (or parmname).

You can find total description from this link 您可以从此链接中找到完整的描述

https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/configuring-parameters-and-parameter-data-types?view=netframework-4.8#working-with-parameter-placeholders https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/configuring-parameters-and-parameter-data-types?view=netframework-4.8#working-with-parameter-placeholders

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM