[英]Entity Framework, devArt, and Oracle VarChar params
Hello: I am using devArt's Oracle Connect to work with Entity Framework 4.1 POCO's and Oracle.您好:我正在使用 devArt 的 Oracle Connect 与 Entity Framework 4.1 POCO 和 Oracle 一起使用。
I have a problem with certain queries where the Oracle column type is Char (fixed-length).我对 Oracle 列类型为 Char(固定长度)的某些查询有疑问。 The parameter that is used in the generated SQL query is formatted as a VarChar instead of a Char, and it is causing my queries to return zero rows.
生成的 SQL 查询中使用的参数被格式化为 VarChar 而不是 Char,这导致我的查询返回零行。 Is there some way to force EntityFramework/DevArt to pad the parameter?
有什么方法可以强制 EntityFramework/DevArt 填充参数吗?
Here's an example of the problem (querying for a username).这是问题的一个示例(查询用户名)。 This code should return rows, but it does not.
此代码应该返回行,但它没有。
string aUserName = "Test";
var query = from u in users
where u.UserName == aUserName
select u;
If I change the first line of code to:如果我将第一行代码更改为:
string aUserName = "Test".PadRight(20);
Then it works (the Oracle column is Char(20)).然后它工作(Oracle 列是 Char(20))。 I would like to not have to do the padding (I don't have to with SQL Server).
我不想做填充(我不需要 SQL 服务器)。 Is there some configuration change that I can make?
我可以进行一些配置更改吗? A connection string switch?
连接字符串开关? An Attribute on my POCO?
我的 POCO 的一个属性?
You have two options:你有两个选择:
1. Do what you did and pad right the user name string variable. 1. 做你所做的并填充用户名字符串变量。
2. remove empty chars - trim right the username field. 2.删除空字符 - 修剪用户名字段。
Other option:其他选项:
string aUserName = "Test";
var query = users.select(x => string.Join(string.Empty, x.UserName).TrimEnd()).
where(x => x==aUserName)
(this will return you the user names and not the whole user objects) (这将返回用户名而不是整个用户对象)
Hope this helps.希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.