Hi all,
I've used NHibernate for a while, but recently I've had to use it with
Sybase for the first time and I've run into a problem. I've created a
workaround, but I'm not sure if it's the right thing to do or not.
Background:
I am using the SybaseAdoNet12ClientDriver and SybaseAdoNet12Dialect
with NH-to-linq.
The database is Sybase Server Enterprise 12.5.
The mappings are specified using FluentNH.
Problem:
Querying a table using Linq didn't return any results despite the data
definitely being in the database. Using NHProf I can see that the
correct SQL is being generated so NH-to-Linq isn't the problem. After
stepping through the NH code I saw that it definitely wasn't getting
any rows back from the database. I eventually realised that this was
due to a where clause on a sybase 'char' column. NH was creating a
DbParameter of type 'StringFixedLengthSqlType' but Sybase required it
to be an AnsiString instead. Modifying this when debugging caused the
query to work correctly
To fix this I've created my own NH driver as below:
public class MyNewSybaseDriver : SybaseAdoNet12ClientDriver
{
protected override void InitializeParameter(IDbDataParameter
dbParam, string name, NHibernate.SqlTypes.SqlType sqlType)
{
var fixedStringType = sqlType as
NHibernate.SqlTypes.StringFixedLengthSqlType;
if (fixedStringType != null)
{
dbParam.DbType = System.Data.DbType.AnsiString;
dbParam.ParameterName = FormatNameForParameter(name);
}
else
{
base.InitializeParameter(dbParam, name, sqlType);
}
}
}
Is this the best way to work-around this issue? Is this a bug with
the Sybase driver or am I doing something wrong? I must admit I know
very little about Sybase, having only used MSSql & Oracle in the past.
Any feedback greatly appreciated,
Thanks,
Simon.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---