Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -299,17 +299,36 @@ public static class EfMappingFactory
{
private static Dictionary<Type, EfMapping> cache = new Dictionary<Type, EfMapping>();

private static object lckObj = new object();

public static EfMapping GetMappingsForContext(DbContext context)
{
var type = context.GetType();

EfMapping mapping;

//Try our cache lookup. If we find an item in the cache
//there is no reason to obtain a lock and limit this part
//of the code to a single thread
if (!cache.TryGetValue(type, out mapping))
{
mapping = new EfMapping(context);
cache.Add(type, mapping);
//if the cache lookup fails lock so only a single thread
//at a time can access the add code
lock (lckObj)
{
//Check the cache again. If 2 threads failed the first cache lookup
//the first thread will add the item to the cache
//the second thread will wait on the lock and then pull the item from
//cache.
if (!cache.TryGetValue(type, out mapping))
{
mapping = new EfMapping(context);
cache.Add(type, mapping);
}
}
}

return mapping;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void InsertItems<T>(IEnumerable<T> items, string schema, string tableName

public void UpdateItems<T>(IEnumerable<T> items, string schema, string tableName, IList<ColumnMapping> properties, DbConnection storeConnection, int? batchSize, UpdateSpecification<T> updateSpecification)
{
var tempTableName = "temp_" + tableName + "_" + DateTime.Now.Ticks;
var tempTableName = "temp_" + tableName + "_" + Guid.NewGuid().ToString("N");
var columnsToUpdate = updateSpecification.Properties.Select(p => p.GetPropertyName()).ToDictionary(x => x);
var filtered = properties.Where(p => columnsToUpdate.ContainsKey(p.NameOnObject) || p.IsPrimaryKey).ToList();
var columns = filtered.Select(c => "[" + c.NameInDatabase + "] " + c.DataType);
Expand Down