简体   繁体   中英

Microsoft.Data.SqlClient.SqlBuffer Unable to cast object of type 'System.String' to type 'System.Guid'

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](IQueryable 1 source, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable 1 source, CancellationToken cancellationToken) at AutoMapper.AspNet.OData.QueryableExtensions.GetAsync[TModel,TData](IQueryable 1 query, IMapper mapper, Expression 1 filter, Expression 1 queryFunc, ICollection 1 includeProperties, AsyncSettings asyncSettings) at AutoMapper.AspNet.OData.QueryableExtensions.GetAsync[TModel,TData](IQueryable 1 query, IMapper mapper, ODataQueryOptions 1 options, QuerySettings querySettings) at AutoMapper.AspNet.OData.QueryableExtensions.GetAsync[TModel,TData](IQueryable 1 options, QuerySettings querySettings) at AutoMapper.AspNet.OData.QueryableExtensions.GetAsync[TModel,TData](IQueryable 1 query, IMapper mapper, ODataQueryOptions 1 options, HandleNullPropagationOption handleNullPropagation) at TRKAPI.Controllers.RecordsController.GetTaskRecord(ODataQueryOptions 1 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.

  1. I transfered data to temp table.
  2. I deleted from the table in question.
  3. I altered the column
  4. Running
SELECT DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'TaskRecord'
  AND COLUMN_NAME = 'TransactionId'

Returns:

DATA_TYPE uniqueidentifier

  1. I then inserted from the temp table, casting the transactionid column into a uniquidentifier
  2. Taking a value from the column and checking it as a valid guid returns valid.
  3. 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?

Well I feel stupid. I had three environments, made the update in one db, but the appsettings was set to another.

Disregard. Sorry.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM