diff --git a/Source/EntityFramework.Extended/Dynamic/DynamicQueryable.cs b/Source/EntityFramework.Extended/Dynamic/DynamicQueryable.cs index b33d8d5..a183e7f 100644 --- a/Source/EntityFramework.Extended/Dynamic/DynamicQueryable.cs +++ b/Source/EntityFramework.Extended/Dynamic/DynamicQueryable.cs @@ -287,8 +287,19 @@ public Type GetDynamicClass(IEnumerable 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; } @@ -300,34 +311,26 @@ public Type GetDynamicClass(IEnumerable 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 } } diff --git a/readme.md b/readme.md index 9bc25fa..547d3bb 100644 --- a/readme.md +++ b/readme.md @@ -42,7 +42,7 @@ A current limitations of the Entity Framework is that in order to update or dele **Deleting** //delete all users where FirstName matches - context.Users.Delete(u => u.FirstName == "firstname"); + context.Users.Where(u => u.FirstName == "firstname").Delete(); **Update**