Question

I've got some EF/LINQ statements that I need to be case-insensitive text searches, but our oracle database is case sensitive. How can I execute the necessary ALTER SESSION statement at the connection/command level so that it will affect the subsequent same-context calls?

Command I think I need to run (OTN Thread)

ALTER SESSION SET NLS_SORT=BINARY_CI

I'm aware of both Database.ExecuteSqlCommand and Database.Connection.CreateCommand as methods, but I can't figure out the 'when'. If I manually try to do this to the context after creation but before the LINQ, I have to manually open & close the connection, and then it seems to be a different transaction as the LINQ, and doesn't seem to be applying.

Was it helpful?

Solution

Technically this is not a solution to your question of how to inject ALTER SESSION SET NLS_SORT=BINARY_CI into a query, but it may help you with your insensitive case search, just use .ToLower() .

OTHER TIPS

The first option would be to ask the DBA to add a "login trigger" to the DB account you are using. The disadvantage there is two fold: One it will be set for every command, and two the DBA will laugh at you for not simply doing the oracle defacto "upper" on everything.

These guys seemed to pull it off using the ExecuteStoreCommand off of the context. I'm not a fan of EF so I can't help much here, but I'd guess you'd need to execute your linq query inside of that same context? http://blogs.planetsoftware.com.au/paul/archive/2012/07/31/ef4-part-10-database-agnostic-linq-to-entities-part-2.aspx

You may be able to use one of the "executing" methods in the command interception feature in EF: http://msdn.microsoft.com/en-us/data/dn469464#BuildingBlocks

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top