You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If properties are mapped using quotes like Map("[field]") or FluentMapper.Column("[field]"), then when executing Insert or BulkInsert it throws an exception.
Exception Message on Insert:
Microsoft.Data.SqlClient.SqlException(0x80131904): Must declare the scalar variable "@IdFile".
at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlExceptionexception,BooleanbreakConnection, Action`1wrapCloseInAction)
at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlExceptionexception,BooleanbreakConnection, Action`1wrapCloseInAction)
at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObjectstateObj,BooleancallerHasConnectionLock,BooleanasyncClose)
at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehaviorrunBehavior,SqlCommandcmdHandler,SqlDataReaderdataStream,BulkCopySimpleResultSetbulkCopyHandler,TdsParserStateObjectstateObj,Boolean&dataReady)
at Microsoft.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at Microsoft.Data.SqlClient.SqlDataReader.get_MetaData()
at Microsoft.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReaderds,RunBehaviorrunBehavior,StringresetOptionsString,BooleanisInternal,BooleanforDescribeParameterEncryption,BooleanshouldCacheForAlwaysEncrypted)
at Microsoft.Data.SqlClient.SqlCommand.CompleteAsyncExecuteReader(BooleanisInternal,BooleanforDescribeParameterEncryption)
at Microsoft.Data.SqlClient.SqlCommand.InternalEndExecuteReader(IAsyncResultasyncResult,BooleanisInternal,StringendMethod)
at Microsoft.Data.SqlClient.SqlCommand.EndExecuteReaderInternal(IAsyncResultasyncResult)
at Microsoft.Data.SqlClient.SqlCommand.EndExecuteReaderAsync(IAsyncResultasyncResult)
at Microsoft.Data.SqlClient.SqlCommand.EndExecuteReaderAsyncCallback(IAsyncResultasyncResult)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResultiar, Func`2endFunction, Action`1endAction, Task`1promise,BooleanrequiresSynchronization)---Endof stack trace from previous location ---at RepoDb.DbConnectionExtension.InsertAsyncInternalBase[TEntity,TResult](IDbConnectionconnection,StringtableName,TEntityentity, IEnumerable`1fields,Stringhints, Nullable`1commandTimeout,StringtraceKey,IDbTransactiontransaction,ITracetrace,IStatementBuilderstatementBuilder,CancellationTokencancellationToken)in/var/home/dyskette/Proyectos/github/RepoDB/RepoDb.Core/RepoDb/Operations/DbConnection/Insert.cs:line 772
Exception Message on BulkInsert:
System.MissingFieldException: There are no field(s) found forthisoperation.atRepoDb.SqlConnectionExtension.BulkInsertAsyncInternalBase[TEntity](SqlConnectionconnection,StringtableName,IEnumerable`1entities,IEnumerable`1mappings,SqlBulkCopyOptionsoptions,Stringhints,Nullable`1bulkCopyTimeout,Nullable`1batchSize,Nullable`1isReturnIdentity,Nullable`1usePhysicalPseudoTempTable,SqlTransactiontransaction,CancellationTokencancellationToken)in/var/home/dyskette/Proyectos/github/RepoDB/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Base/BulkInsert.cs:line 500
Basically both errors happen because the comparison between FieldCache.Get result and DbField.Cache result don't match. The former has the quotes I added, the latter fetches the fields without the quotes.
Which means that on Insert, it doesn't remove the identity from the InsertableFields variable here. And on BulkInsert it removes all fields that don't match, which is all of them, here.
In retrospective, I find it silly to be using quotes for the properties now. But, I just copied and pasted the names with quotes as they were generated by the Azure Data Studio and didn't think anything of it. It never crossed my mind that I was doing something wrong there. I was going in circles until I downloaded the source code, added it as references to my project and debugged it. 😢
Schema and Model:
CREATETABLE[dbo].[NasFile]([IdFile]INTIDENTITY(1,1) NOT NULL PRIMARY KEY,[FilePath]NVARCHAR(500) NULL,);
Model that corresponds the schema.
[Map("[dbo].[NasFile]")]publicclassBusinessFile{/// <summary>/// Id of file/// </summary>[Map("[IdFile]")]publicintId{get;set;}/// <summary>/// Path of the file in NAS/// </summary>[Map("[FilePath]")]publicstring?Path{get;set;}}
Library Version:
RepoDb v1.13.1
RepoDb.SqlServer v1.13.1
RepoDb.SqlServer.BulkOperations v1.13.1
The text was updated successfully, but these errors were encountered:
Bug Description
If properties are mapped using quotes like
Map("[field]")
orFluentMapper.Column("[field]")
, then when executing Insert or BulkInsert it throws an exception.Exception Message on Insert:
Exception Message on BulkInsert:
Basically both errors happen because the comparison between
FieldCache.Get
result andDbField.Cache
result don't match. The former has the quotes I added, the latter fetches the fields without the quotes.Which means that on
Insert
, it doesn't remove the identity from theInsertableFields
variable here. And onBulkInsert
it removes all fields that don't match, which is all of them, here.In retrospective, I find it silly to be using quotes for the properties now. But, I just copied and pasted the names with quotes as they were generated by the Azure Data Studio and didn't think anything of it. It never crossed my mind that I was doing something wrong there. I was going in circles until I downloaded the source code, added it as references to my project and debugged it. 😢
Schema and Model:
Model that corresponds the schema.
Library Version:
The text was updated successfully, but these errors were encountered: