Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Fix concurrency bug in Batch Update and Delete
GetDynamicClass method: added the double check for "signature" in "classes" dictionary to avoid concurrency issues.
CreateDynamicClass: removed the upgrade to write lock because managed by the caller "GetDynamicClass" method.
  • Loading branch information
Liu79 committed Apr 8, 2013
commit b04ef7e1fdeb7ab700763d1b92d16ccf8beccba0
53 changes: 28 additions & 25 deletions Source/EntityFramework.Extended/Dynamic/DynamicQueryable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,19 @@ public Type GetDynamicClass(IEnumerable<DynamicProperty> properties)
Type type;
if (!classes.TryGetValue(signature, out type))
{
type = CreateDynamicClass(signature.properties);
classes.Add(signature, type);
LockCookie cookie = rwLock.UpgradeToWriterLock(Timeout.Infinite);
try
{
if (!classes.TryGetValue(signature, out type))
{
type = CreateDynamicClass(signature.properties);
classes.Add(signature, type);
}
}
finally
{
rwLock.DowngradeFromWriterLock(ref cookie);
}
}
return type;
}
Expand All @@ -298,34 +309,26 @@ public Type GetDynamicClass(IEnumerable<DynamicProperty> properties)

Type CreateDynamicClass(DynamicProperty[] properties)
{
LockCookie cookie = rwLock.UpgradeToWriterLock(Timeout.Infinite);
try
{
string typeName = "DynamicClass" + (classCount + 1);
#if ENABLE_LINQ_PARTIAL_TRUST
new ReflectionPermission(PermissionState.Unrestricted).Assert();
#endif
try
{
TypeBuilder tb = this.module.DefineType(typeName, TypeAttributes.Class |
TypeAttributes.Public, typeof(DynamicClass));
FieldInfo[] fields = GenerateProperties(tb, properties);
GenerateEquals(tb, fields);
GenerateGetHashCode(tb, fields);
Type result = tb.CreateType();
classCount++;
return result;
}
finally
{
string typeName = "DynamicClass" + (classCount + 1);
#if ENABLE_LINQ_PARTIAL_TRUST
PermissionSet.RevertAssert();
new ReflectionPermission(PermissionState.Unrestricted).Assert();
#endif
}
try
{
TypeBuilder tb = this.module.DefineType(typeName, TypeAttributes.Class |
TypeAttributes.Public, typeof(DynamicClass));
FieldInfo[] fields = GenerateProperties(tb, properties);
GenerateEquals(tb, fields);
GenerateGetHashCode(tb, fields);
Type result = tb.CreateType();
classCount++;
return result;
}
finally
{
rwLock.DowngradeFromWriterLock(ref cookie);
#if ENABLE_LINQ_PARTIAL_TRUST
PermissionSet.RevertAssert();
#endif
}
}

Expand Down