Batch processing issue (LINQ to SQL)
In order to access inserted records before calling SubmitChanges() please use the following code below:
- 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: ...
SQL Complete tabs (SSMS)
You may change settings for your tabs layout using these settings: In case you need to create custom tab names, please use this tab: You may find more information with tutorials in our documentation: ...
SQL Complete activation
Unless activated, dbForge SQL Complete works on the trial basis for 30 days. When the trial expires, dbForge SQL Complete must be activated with a purchased activation key. Note To check the current status of your trial period or the status of your ...
Assistance with SQL Script Creation
We strive to provide support for a wide range of technical issues; however, we do not offer assistance with creating SQL scripts. Please note that our support team primarily focuses on addressing issues related to the functionality and performance of ...