Reputation: 18155
I have an EF model defined as follows:
public class ProgramManagerRolePermission
{
[Key, Column(Order = 1)]
public Guid ShardKey { get; set; }
[Key, Column(Order = 2)]
public Guid RoleId { get; set; }
[Key, Column(Order = 3)]
public Guid PermissionId { get; set; }
[ForeignKey(nameof(RoleId))]
public virtual ProgramManagerRole Role { get; set; }
[ForeignKey(nameof(PermissionId))]
public virtual ProgramManagerPermission Permission { get; set; }
}
I've got the following test code:
using (var repo = IdentityProgramRepositoryFactory.Get())
{
var role = repo.ProgramManagerRoles
.Include(r => r.Permissions)
.SingleOrDefault(r => r.Id == roleId);
role.Permissions.Should().BeEquivalentTo(new[] {
new Repo.ProgramManagerRolePermission
{
PermissionId = ProgramManagerPermissions.GrantOrRevokeRoles.Id,
RoleId = roleId,
ShardKey = identityProgramId
},
new Repo.ProgramManagerRolePermission
{
PermissionId = ProgramManagerPermissions.ManageNode.Id,
RoleId = roleId,
ShardKey = identityProgramId
}
}, options => options.ExcludingNestedObjects());
}
When I run it the test fails because an ObjectDisposedException
is thrown with the message:
Safe handle has been closed
If I change the last line to:
}, options => options.Excluding(p => p.Role).Excluding(p => p.Permission));
Then the test runs successfully.
The only two nested objects are Role
and Permission
. When I exclude them explicitly the test works, when I tell it to exclude all nested objects it appears to still be trying to navigate through them.
Anyone run into this before? Any explanation as to why what I think should be happening isn't?
Upvotes: 2
Views: 194
Reputation: 8889
You're using ExcludingNestedObjects
, which means it will not do a structural comparison between the objects exposed by the Role
and Permission
objects. Those are properties of your root object. But it will still try to do a simple equality check.
Upvotes: 2