Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ODP.NET / EF6 - Force bind as CHAR

user10932370Jan 30 2015 — edited Apr 7 2015

I'm starting a project with EF6 and ODP.NET and I'm having trouble performing look-ups based on fixed-length CHAR columns.

The following code returns no results, even though this user exists in the database.

using (var context = new Entities())

{

     var search = "testuser";

     var result = context.Users

                    .Where(u => u.UserName == search)

                    .FirstOrDefault();

}

I know I can get around this by padding the search string or by trimming the database column, but I'm looking for an alternate solution.

I noticed that if I execute the query directly using OracleConnection/OracleCommand, then it works. Is there an attribute or anything I can add to the entity class to cause ODP.NET to bind the variable as an OracleDbType.Char?

Basically, I'm looking for a way to reproduce the following behavior from EF6:

var cmd = new OracleCommand("SELECT * FROM users WHERE user_name = :p0", conn);

cmd.Parameters.Add(":p0", OracleDbType.Char).Value = "testuser";

I also tested with Devart's dotConnect Oracle driver. Using that driver, I can do a look-up successfully by adding the following line of code. I would prefer to use ODP.NET over dotConnect, though. It seems ODP.NET is ignoring this property because it has no effect when using ODP.NET. Is there an equivalent to this that ODP.NET will recognize?

modelBuilder.Entity<Users>()

                .Property(u => u.UserName

               .IsFixedLength();

If I could, I would just change the column type to VARCHAR2 and wash my hands of this, but unfortunately, that is not an option at the moment. Any help you can provide would be very much appreciated!

Thanks,

Matt

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 5 2015
Added on Jan 30 2015
1 comment
973 views