Page 1 of 1

Convert from int to string on both Oracle and SQL Server

Posted: Wed 26 Jun 2013 00:21
by Werlang
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

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

Posted: Wed 26 Jun 2013 15:44
by Shalex
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
});

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

Posted: Wed 26 Jun 2013 16:20
by Werlang
Thank you Shalex.

Best regards