Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EFBatchOperation InsertAll "Sequence contains more than one element" #83

Open
RNetview opened this issue May 6, 2016 · 2 comments · May be fixed by #120
Open

EFBatchOperation InsertAll "Sequence contains more than one element" #83

RNetview opened this issue May 6, 2016 · 2 comments · May be fixed by #120

Comments

@RNetview
Copy link

RNetview commented May 6, 2016

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()

@norcino
Copy link

norcino commented Nov 10, 2016

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.

@norcino
Copy link

norcino commented Nov 10, 2016

From the note in the main page:

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants