Batch processing issue (LINQ to SQL)

Batch processing issue (LINQ to SQL)

In order to access inserted records before calling SubmitChanges() please use the following code below:

  1. public static List<T> WhereOrInserted<T>(this Table<T> table, Expression<Func<T, bool>> predicate) where T : class { var result = table.Where(predicate).ToList(); if (result != null && result.Count != 0) return result; result = table.Context.GetChangeSet().Inserts.Where(a => a.GetType() == typeof(T)) .Select(a => a as T) .ToList(); return result; } public static T FirstOrInserted<T>(this Table<T> table, Expression<Func<T, bool>> predicate) where T : class { var result = table.First(predicate); if (result != null) return result; result = table.Context.GetChangeSet().Inserts.Where(a => a.GetType() == typeof(T)) .Select(a => a as T) .First(); return result; } public static T FirstOrDefaultOrInserted<T>(this Table<T> table, Expression<Func<T, bool>> predicate) where T : class { var result = table.FirstOrDefault(predicate); if (result != null) return result; result = table.Context.GetChangeSet().Inserts.Where(a => a.GetType() == typeof(T)) .Select(a => a as T) .FirstOrDefault(); return result; }
    • Related Articles

    • How to Enable Logging for SQL Complete

      Logging is required to capture detailed information about failures and issues in the program. If reproducing or diagnosing a problem is difficult, logging helps in performing a deeper investigation. This guide applies to the following product: ...
    • How to Enable Logging for Source Control and Data Pump for SQL Server

      Logging is essential for capturing detailed information about failures and issues in the program. If reproducing or diagnosing a problem is difficult, logging helps in providing a deeper investigation. This guide applies to the following products: ...
    • dbForge SQL Tools Missing After Installing or Updating SSMS

      Typically, upon the initial launch of SSMS after you install SQL Tools for the first time, there is a brief registration process that takes no more than 1-2 minutes, depending on your system's performance. If SQL Tools are still missing after this ...
    • what sql- syntax can be used when using ODBC Drivers?

      Please be informed, that Devart ODBC Drivers uses the SQLite engine to execute SQL queries, so in order to build queries with it you can use the syntax used in SQLite: http://www.sqlite.org/lang.html
    • Tool Version Does Not Match SQL Tools Version

      In some cases, users may download SQL Tools or the Compare Bundle of one version, but when installed, the individual tool versions do not match the version of the downloaded package. The reason for this is that SQL Tools is essentially a bundle ...