Error: System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Guid'. at Microsoft.Data.SqlClient.SqlBuffer.get_Guid() at Microsoft.Data.SqlClient.SqlDataReader.GetGuid(Int32 i) at lambda_method88(Closure , QueryContext , DbDataReader , ResultContext , SingleQueryResultCoordinator ) at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable
1.AsyncEnumerator.MoveNextAsync() at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable1 source, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable1 source, CancellationToken cancellationToken) at AutoMapper.AspNet.OData.QueryableExtensions.GetAsync[TModel,TData](IQueryable1 query, IMapper mapper, Expression1 filter, Expression1 queryFunc, ICollection1 includeProperties, AsyncSettings asyncSettings) at AutoMapper.AspNet.OData.QueryableExtensions.GetAsync[TModel,TData](IQueryable1 query, IMapper mapper, ODataQueryOptions1 options, QuerySettings querySettings) at AutoMapper.AspNet.OData.QueryableExtensions.GetAsync[TModel,TData](IQueryable1 query, IMapper mapper, ODataQueryOptions1 options, HandleNullPropagationOption handleNullPropagation) at TRKAPI.Controllers.RecordsController.GetTaskRecord(ODataQueryOptions1 options) in
Line 80 is cited as cause
_context.TaskRecord.GetAsync(_mapper, options, HandleNullPropagationOption.Default);
This started happening after changing a column in the table from string to uniqueidentifier.
- I transfered data to temp table.
- I deleted from the table in question.
- I altered the column
- Running
SELECT DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'TaskRecord'
AND COLUMN_NAME = 'TransactionId'
Returns:
DATA_TYPE uniqueidentifier
- I then inserted from the temp table, casting the transactionid column into a uniquidentifier
- Taking a value from the column and checking it as a valid guid returns valid.
- I updated the contract (dto), model and there is no reference to a column in the db context.
I'm not really sure where to look next, ideas?