Convert from int to string on both Oracle and SQL Server

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
Werlang
Posts: 4
Joined: Wed 19 Jun 2013 20:04

Convert from int to string on both Oracle and SQL Server

Post by Werlang » Wed 26 Jun 2013 00:21

Hello

I have code like this:

Code: Select all

string param_id = ...

from p in Person
where p.BankId.ToString() == param_id
select new 
{
	Id = p.Id,
	Name = p.Name,
	Date = p.Date,
	BankId = p.BankId
}

This currently doesn't work. On SQL Server, we can use SqlFunctions.StringConvert().
On Oracle, we use OracleFunctions.ToChar()

The problem is that we need to support both databases at the same time. How this compatibility should be accomplished?

Thank you

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Convert from int to string on both Oracle and SQL Server

Post by Shalex » Wed 26 Jun 2013 15:44

Werlang wrote:The problem is that we need to support both databases at the same time.
There is no way.

Please use the following workaround:

Code: Select all

string param_id = ...

var query = from p in Person;

if (isSqlServer)
  query = query.Where(p => SqlFunctions.StringConvert(p.BankId));
else // is Oracle
  query = query.Where(p => OracleFunctions.ToChar(p.BankId));

var finalQuery = query.Select(p => new
{
   Id = p.Id,
   Name = p.Name,
   Date = p.Date,
   BankId = p.BankId
});

Werlang
Posts: 4
Joined: Wed 19 Jun 2013 20:04

Re: Convert from int to string on both Oracle and SQL Server

Post by Werlang » Wed 26 Jun 2013 16:20

Thank you Shalex.

Best regards

Post Reply