conversion problem

May 16, 2012 at 9:20 AM
Edited May 16, 2012 at 9:23 AM

When I try to insert/update something that is null I got an exception
I use this construction
var builder = context.Insert("Orders");
builder = builder.Column("Comments", order.Comments);
then builder.ExecuteReturnLastId<long>()

; fails with the exception below:

Implicit conversion from data type sql_variant to nvarchar is not allowed. Use the CONVERT function to run this query.

The same problem occur when I have a Nullable<decimal>

Implicit conversion from data type sql_variant to decimal is not allowed. Use the CONVERT function to run this query.

The workaround for insert was :
if(order.Comments != null)
builder = builder.Column("Comments", order.Comments);

But now I have to update and don't know what to do.

Here is the stack trace

System.Data.SqlClient.SqlException (0x80131904): Implicit conversion from data type sql_variant to nvarchar is not allowed. Use the CONVERT function to run this query.
   at FluentData.ExecuteQueryHandler.HandleQueryException(Exception exception)
   at FluentData.ExecuteQueryHandler.ExecuteQuery(Boolean useReader, Action action)
   at FluentData.Providers.SqlServer.SqlServerProvider.ExecuteReturnLastId[T](DbCommandData data, String identityColumnName)
   at FluentData.DbCommand.ExecuteReturnLastId[T]()
   at FluentData.BaseInsertBuilder.ExecuteReturnLastId[T]()

May 17, 2012 at 2:20 PM

Should be fixed now. See the issue you created under the Issue tracker for more information.