Closed gregoryagu closed 7 months ago
I was able to get this working by defining the Entity Type as a TimeSpan, instead of a TimeOnly. Then no exception was thrown. I then convert it to a TimeOnly.
public TimeSpan TimeOnlyTest {get;set;}
public TimeOnly MyTimeOnly
{
get { return TimeOnly.FromTimeSpan(this.TimeOnlyTest); }
set { this.TimeOnlyTest = value.ToTimeSpan(); }
}
I have a Project which uses Sql Server and the TimeOnly data type.
When I attempt to save an entity which has a TimeOnly field, I get the following error message. I searched the docs, but I did not find any mention of TimeOnly, Is there a way to resolve this?
Using version 1.13.0
await connection.UpdateAsync(tutorInfo);
System.InvalidCastException HResult=0x80004002 Message=Failed to convert parameter value from a TimeOnly to a TimeSpan. Source=Microsoft.Data.SqlClient StackTrace: at Microsoft.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType, Boolean& coercedToDataFeed, Boolean& typeChanged, Boolean allowStreaming) at Microsoft.Data.SqlClient.SqlParameter.GetCoercedValue() at Microsoft.Data.SqlClient.SqlParameter.Validate(Int32 index, Boolean isCommandProc) at Microsoft.Data.SqlClient.SqlCommand.BuildParamList(TdsParser parser, SqlParameterCollection parameters, Boolean includeReturnValue) at Microsoft.Data.SqlClient.SqlCommand.BuildExecuteSql(CommandBehavior behavior, String commandText, SqlParameterCollection parameters, _SqlRPC& rpc) at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean isAsync, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSourced989`1.MoveNext()
at Rihisi.Data.DataStore.d 0.MoveNext() in C:\Dev\BlueHatSoftware\Rihisi\V5\Rihisi\Rihisi\Data\DataStore.cs:line 25
1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String method) at Microsoft.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource
1 completion, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String methodName) at Microsoft.Data.SqlClient.SqlCommand.BeginExecuteNonQueryInternal(CommandBehavior behavior, AsyncCallback callback, Object stateObject, Int32 timeout, Boolean inRetry, Boolean asyncWrite) at Microsoft.Data.SqlClient.SqlCommand.BeginExecuteNonQueryAsync(AsyncCallback callback, Object stateObject) at System.Threading.Tasks.TaskFactory1.FromAsyncImpl(Func
3 beginMethod, Func2 endFunction, Action
1 endAction, Object state, TaskCreationOptions creationOptions) at System.Threading.Tasks.TaskFactory1.FromAsync(Func
3 beginMethod, Func2 endMethod, Object state) at Microsoft.Data.SqlClient.SqlCommand.InternalExecuteNonQueryAsync(CancellationToken cancellationToken) --- End of stack trace from previous location --- at RepoDb.DbConnectionExtension.<UpdateAsyncInternalBase>d__1008
1.MoveNext() at RepoDb.DbConnectionExtension.This exception was originally thrown at this call stack: [External Code]
Inner Exception 1: InvalidCastException: Object must implement IConvertible.