开发者

Entity Framework, devArt, and Oracle VarChar params

开发者 https://www.devze.com 2023-03-02 05:05 出处:网络
Hello:I am using devArt\'s Oracle Connect to work with Entity Framework 4.1 POCO\'s and Oracle. I have a problem with certain queries where the Oracle column type is Char (fixed-length).The parameter

Hello: I am using devArt's Oracle Connect to work with Entity Framework 4.1 POCO's and Oracle.

I have a problem with certain queries where the Oracle column type is Char (fixed-length). 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. Is there some way to force EntityFramework/DevArt to pad the parameter?

Here's an example of the problem (querying for a username). This code should return rows, but it d开发者_StackOverflow中文版oes 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)). I would like to not have to do the padding (I don't have to with SQL Server). Is there some configuration change that I can make? A connection string switch? An Attribute on my POCO?


You have two options:
1. Do what you did and pad right the user name string variable.
2. remove empty chars - trim right the username field.

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.


We have replied to you here at our forum.
Please inform us if you encounter any problems with the provided solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消