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
Hi,
I'm unable to use the "InsertAll" method. The error thrown was "Sequence contains more than one element".
I'm using the method in a Repository class library project. This is how I'm making the call EFBatchOperation.For(context, context.Set<T>()).InsertAll(listaObj);
The Table has a PK Field with autoincrement.
And this is the stacktrace:
em System.Linq.Enumerable.Single[TSource](IEnumerable1 source) em EntityFramework.Utilities.EfMapping..ctor(DbContext db) em EntityFramework.Utilities.EfMappingFactory.GetMappingsForContext(DbContext context) em EntityFramework.Utilities.EFBatchOperation2.InsertAll[TEntity](IEnumerable1 items, DbConnection connection, Nullable1 batchSize)
em RepositoryLayer.DAL.Repository1.InserirTodos(IEnumerable1 listaObj) na C:\Sistemas-Netview_Desktop\RoboTerceirizacao\RepositoryLayer\DAL\Repository.cs:linha 50
em RepositoryLayer.DAL.TerceirizacaoTempRepository.InserirImportacao(IEnumerable1 listaObj) na C:\Sistemas-Netview_Desktop\RoboTerceirizacao\RepositoryLayer\DAL\TerceirizacaoTempRepository.cs:linha 34 em BusinessLayer.BLL.TerceirizacaoTemp.InserirImportacao(IEnumerable1 listaObj) na C:\Sistemas-Netview_Desktop\RoboTerceirizacao\BusinessLayer\BLL\TerceirizacaoTemp.cs:linha 42
em Utilidades.Classes.Util.ImportarPlanilhaExcel(String nomeArquivo, DateTime data) na C:\Sistemas-Netview_Desktop\RoboTerceirizacao\Utilidades\Classes\Util.cs:linha 194
em RoboTerceirizacao.Janelas.WImportarPlanilha.ImportarPlanilhaBtnRV_Click(Object sender, RoutedEventArgs e) na C:\Sistemas-Netview_Desktop\RoboTerceirizacao\RoboTerceirizacao\Janelas\WImportarPlanilha.xaml.cs:linha 40
em System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
em System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
em System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
em System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
em System.Windows.Controls.Primitives.ButtonBase.OnClick()
em System.Windows.Controls.Button.OnClick()
em System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
em System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
em System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
em System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
em System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
em System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
em System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
em System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
em System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
em System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
em System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
em System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
em System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
em System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
em System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
em System.Windows.Input.InputManager.ProcessStagingArea()
em System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
em System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
em System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
em System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
em System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
em MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
em MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
em System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
em System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
em System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
em MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
em MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
em System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
em System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
em System.Windows.Window.ShowHelper(Object booleanBox)
em System.Windows.Window.Show()
em System.Windows.Window.ShowDialog()
The text was updated successfully, but these errors were encountered:
I have the same issue, I cannot use anywhere InsertAll anymore after adding a new table mapped with 1 to 1 relation as specification table, if I delete that mapping from the context it works.
You might have a similar situation there.
Inheritance and Bulk insert
Bulk insert should support TPH inheritance. The other inheritance models will most likely not work.
TPH is is a patter that uses one table to store data eventually mapped in many types
I use TPT, so I have on table per Type, but all types involved in the TPT are inherited from a base table. This means that an insert of a "Specification" Type, will cause the insert in 2 different tables, the base and the specification one.
Apparently EntityFramework.Utilities breaks calling InsertAll even if the TPT is not affecting directly tha table where we are inserting the data in batch, to break it is enough to have in the same context an implementation of the TPT pattern.
aliozgur
pushed a commit
to aliozgur/EntityFramework.Utilities
that referenced
this issue
Mar 28, 2018
Hi,
I'm unable to use the "InsertAll" method. The error thrown was "Sequence contains more than one element".
I'm using the method in a Repository class library project. This is how I'm making the call
EFBatchOperation.For(context, context.Set<T>()).InsertAll(listaObj);
The Table has a PK Field with autoincrement.
And this is the stacktrace:
em System.Linq.Enumerable.Single[TSource](IEnumerable
1 source) em EntityFramework.Utilities.EfMapping..ctor(DbContext db) em EntityFramework.Utilities.EfMappingFactory.GetMappingsForContext(DbContext context) em EntityFramework.Utilities.EFBatchOperation
2.InsertAll[TEntity](IEnumerable1 items, DbConnection connection, Nullable
1 batchSize)em RepositoryLayer.DAL.Repository
1.InserirTodos(IEnumerable
1 listaObj) na C:\Sistemas-Netview_Desktop\RoboTerceirizacao\RepositoryLayer\DAL\Repository.cs:linha 50em RepositoryLayer.DAL.TerceirizacaoTempRepository.InserirImportacao(IEnumerable
1 listaObj) na C:\Sistemas-Netview_Desktop\RoboTerceirizacao\RepositoryLayer\DAL\TerceirizacaoTempRepository.cs:linha 34 em BusinessLayer.BLL.TerceirizacaoTemp.InserirImportacao(IEnumerable
1 listaObj) na C:\Sistemas-Netview_Desktop\RoboTerceirizacao\BusinessLayer\BLL\TerceirizacaoTemp.cs:linha 42em Utilidades.Classes.Util.ImportarPlanilhaExcel(String nomeArquivo, DateTime data) na C:\Sistemas-Netview_Desktop\RoboTerceirizacao\Utilidades\Classes\Util.cs:linha 194
em RoboTerceirizacao.Janelas.WImportarPlanilha.ImportarPlanilhaBtnRV_Click(Object sender, RoutedEventArgs e) na C:\Sistemas-Netview_Desktop\RoboTerceirizacao\RoboTerceirizacao\Janelas\WImportarPlanilha.xaml.cs:linha 40
em System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
em System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
em System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
em System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
em System.Windows.Controls.Primitives.ButtonBase.OnClick()
em System.Windows.Controls.Button.OnClick()
em System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
em System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
em System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
em System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
em System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
em System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
em System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
em System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
em System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
em System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
em System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
em System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
em System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
em System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
em System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
em System.Windows.Input.InputManager.ProcessStagingArea()
em System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
em System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
em System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
em System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
em System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
em MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
em MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
em System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
em System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
em System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
em MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
em MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
em System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
em System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
em System.Windows.Window.ShowHelper(Object booleanBox)
em System.Windows.Window.Show()
em System.Windows.Window.ShowDialog()
The text was updated successfully, but these errors were encountered: