Skip to content

Commit

Permalink
Add System.Linq.Async package to work with AsyncEnumerable and `A…
Browse files Browse the repository at this point in the history
…syncEnumerator` (this introduces an ambiguaty, see dotnet/efcore#18124, which will be removed in EF Core 6.0, see dotnet/efcore#18124 (comment), but until then it requires us to call `AsQueryable` on `DbSet` before calling `Where`)
  • Loading branch information
simon-wacker committed Mar 10, 2021
1 parent 72d9781 commit 21ade8f
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Metabase/backend/src/Authorization/CommonAuthorization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ CancellationToken cancellationToken
return null;
}
var wrappedRole =
await context.InstitutionRepresentatives
await context.InstitutionRepresentatives.AsQueryable()
.Where(x =>
x.InstitutionId == institutionId &&
x.UserId == user.Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public ComponentManufacturersByComponentIdDataLoader(
batchScheduler,
dbContextFactory,
(dbContext, ids) =>
dbContext.ComponentManufacturers.Where(x =>
dbContext.ComponentManufacturers.AsQueryable().Where(x =>
ids.Contains(x.ComponentId)
),
x => x.ComponentId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ CancellationToken cancellationToken
{
await using var dbContext =
_dbContextFactory.CreateDbContext();
return await _getQueryable(dbContext)
return await _getQueryable(dbContext).AsQueryable()
.Where(entity => ids.Contains(entity.Id))
.ToDictionaryAsync(
entity => entity.Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public InstitutionDevelopedMethodsByInstitutionIdDataLoader(
batchScheduler,
dbContextFactory,
(dbContext, ids) =>
dbContext.InstitutionMethodDevelopers.Where(x =>
dbContext.InstitutionMethodDevelopers.AsQueryable().Where(x =>
ids.Contains(x.InstitutionId)
),
x => x.InstitutionId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public InstitutionManagedDataFormatsByInstitutionIdDataLoader(
batchScheduler,
dbContextFactory,
(dbContext, ids) =>
dbContext.DataFormats.Where(x =>
dbContext.DataFormats.AsQueryable().Where(x =>
ids.Contains(x.ManagerId)
),
x => x.ManagerId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public InstitutionManufacturedComponentsByInstitutionIdDataLoader(
batchScheduler,
dbContextFactory,
(dbContext, ids) =>
dbContext.ComponentManufacturers.Where(x =>
dbContext.ComponentManufacturers.AsQueryable().Where(x =>
ids.Contains(x.InstitutionId)
),
x => x.InstitutionId
Expand Down
26 changes: 13 additions & 13 deletions Metabase/backend/src/GraphQl/Institutions/InstitutionMutations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ CancellationToken cancellationToken
}
var unknownOwnerIds =
input.OwnerIds.Except(
await context.Users
await context.Users.AsQueryable()
.Where(u => input.OwnerIds.Contains(u.Id))
.Select(u => u.Id)
.ToListAsync(cancellationToken)
Expand Down Expand Up @@ -107,7 +107,7 @@ CancellationToken cancellationToken
);
}
var institution =
await context.Institutions
await context.Institutions.AsQueryable()
.Where(i => i.Id == input.InstitutionId)
.SingleOrDefaultAsync(cancellationToken)
.ConfigureAwait(false);
Expand Down Expand Up @@ -162,7 +162,7 @@ CancellationToken cancellationToken
);
}
var institution =
await context.Institutions
await context.Institutions.AsQueryable()
.Where(i => i.Id == input.InstitutionId)
.SingleOrDefaultAsync(cancellationToken)
.ConfigureAwait(false);
Expand Down Expand Up @@ -210,7 +210,7 @@ CancellationToken cancellationToken
);
}
var errors = new List<AddInstitutionRepresentativeError>();
if (!await context.Institutions
if (!await context.Institutions.AsQueryable()
.Where(i => i.Id == input.InstitutionId)
.AnyAsync(cancellationToken)
.ConfigureAwait(false)
Expand All @@ -224,7 +224,7 @@ CancellationToken cancellationToken
)
);
}
if (!await context.Users
if (!await context.Users.AsQueryable()
.Where(u => u.Id == input.UserId)
.AnyAsync(cancellationToken)
.ConfigureAwait(false)
Expand All @@ -242,7 +242,7 @@ CancellationToken cancellationToken
{
return new AddInstitutionRepresentativePayload(errors.AsReadOnly());
}
if (await context.InstitutionRepresentatives
if (await context.InstitutionRepresentatives.AsQueryable()
.Where(r =>
r.InstitutionId == input.InstitutionId
&& r.UserId == input.UserId
Expand Down Expand Up @@ -299,7 +299,7 @@ CancellationToken cancellationToken
);
}
var errors = new List<RemoveInstitutionRepresentativeError>();
if (!await context.Institutions
if (!await context.Institutions.AsQueryable()
.Where(i => i.Id == input.InstitutionId)
.AnyAsync(cancellationToken)
.ConfigureAwait(false)
Expand All @@ -313,7 +313,7 @@ CancellationToken cancellationToken
)
);
}
if (!await context.Users
if (!await context.Users.AsQueryable()
.Where(u => u.Id == input.UserId)
.AnyAsync(cancellationToken)
.ConfigureAwait(false)
Expand All @@ -332,7 +332,7 @@ CancellationToken cancellationToken
return new RemoveInstitutionRepresentativePayload(errors.AsReadOnly());
}
var institutionRepresentative =
await context.InstitutionRepresentatives
await context.InstitutionRepresentatives.AsQueryable()
.Where(r =>
r.InstitutionId == input.InstitutionId
&& r.UserId == input.UserId
Expand Down Expand Up @@ -400,7 +400,7 @@ CancellationToken cancellationToken
);
}
var errors = new List<ChangeInstitutionRepresentativeRoleError>();
if (!await context.Institutions
if (!await context.Institutions.AsQueryable()
.Where(i => i.Id == input.InstitutionId)
.AnyAsync(cancellationToken)
.ConfigureAwait(false)
Expand All @@ -414,7 +414,7 @@ CancellationToken cancellationToken
)
);
}
if (!await context.Users
if (!await context.Users.AsQueryable()
.Where(u => u.Id == input.UserId)
.AnyAsync(cancellationToken)
.ConfigureAwait(false)
Expand All @@ -433,7 +433,7 @@ CancellationToken cancellationToken
return new ChangeInstitutionRepresentativeRolePayload(errors.AsReadOnly());
}
var institutionRepresentative =
await context.InstitutionRepresentatives
await context.InstitutionRepresentatives.AsQueryable()
.Where(r =>
r.InstitutionId == input.InstitutionId
&& r.UserId == input.UserId
Expand Down Expand Up @@ -480,7 +480,7 @@ private static async Task<bool> ExistsOtherInstitutionOwner(
CancellationToken cancellationToken
)
{
return await context.InstitutionRepresentatives
return await context.InstitutionRepresentatives.AsQueryable()
.Where(r =>
r.InstitutionId == institutionId
&& r.UserId != userId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public InstitutionOperatedDatabasesByInstitutionIdDataLoader(
batchScheduler,
dbContextFactory,
(dbContext, ids) =>
dbContext.Databases.Where(x =>
dbContext.Databases.AsQueryable().Where(x =>
ids.Contains(x.OperatorId)
),
x => x.OperatorId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public InstitutionRepresentativesByInstitutionIdDataLoader(
batchScheduler,
dbContextFactory,
(dbContext, ids) =>
dbContext.InstitutionRepresentatives.Where(x =>
dbContext.InstitutionRepresentatives.AsQueryable().Where(x =>
ids.Contains(x.InstitutionId)
),
x => x.InstitutionId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public InstitutionMethodDevelopersByMethodIdDataLoader(
batchScheduler,
dbContextFactory,
(dbContext, ids) =>
dbContext.InstitutionMethodDevelopers.Where(x =>
dbContext.InstitutionMethodDevelopers.AsQueryable().Where(x =>
ids.Contains(x.MethodId)
),
x => x.MethodId
Expand Down
4 changes: 2 additions & 2 deletions Metabase/backend/src/GraphQl/Methods/MethodMutations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ CancellationToken cancellationToken
// }
var unknownInstitutionDeveloperIds =
input.InstitutionDeveloperIds.Except(
await context.Users
await context.Users.AsQueryable()
.Where(x => input.InstitutionDeveloperIds.Contains(x.Id))
.Select(x => x.Id)
.ToListAsync(cancellationToken)
Expand All @@ -69,7 +69,7 @@ await context.Users
}
var unknownUserDeveloperIds =
input.UserDeveloperIds.Except(
await context.Users
await context.Users.AsQueryable()
.Where(u => input.UserDeveloperIds.Contains(u.Id))
.Select(u => u.Id)
.ToListAsync(cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public UserMethodDevelopersByMethodIdDataLoader(
batchScheduler,
dbContextFactory,
(dbContext, ids) =>
dbContext.UserMethodDevelopers.Where(x =>
dbContext.UserMethodDevelopers.AsQueryable().Where(x =>
ids.Contains(x.MethodId)
),
x => x.MethodId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public UserDevelopedMethodsByUserIdDataLoader(
batchScheduler,
dbContextFactory,
(dbContext, ids) =>
dbContext.UserMethodDevelopers.Where(x =>
dbContext.UserMethodDevelopers.AsQueryable().Where(x =>
ids.Contains(x.UserId)
),
x => x.UserId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public UserRepresentedInstitutionsByUserIdDataLoader(
batchScheduler,
dbContextFactory,
(dbContext, ids) =>
dbContext.InstitutionRepresentatives.Where(x =>
dbContext.InstitutionRepresentatives.AsQueryable().Where(x =>
ids.Contains(x.UserId)
),
x => x.UserId
Expand Down
1 change: 1 addition & 0 deletions Metabase/backend/src/Metabase.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<ItemGroup>
<!-- <PackageReference Include="AutoMapper" Version="10.1.1" /> -->
<!-- <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.0" /> -->
<PackageReference Include="System.Linq.Async" Version="5.0.0" />
<PackageReference Include="HotChocolate" Version="11.0.9" />
<PackageReference Include="HotChocolate.AspNetCore" Version="11.0.9" />
<PackageReference Include="HotChocolate.AspNetCore.Authorization" Version="11.0.9" />
Expand Down

0 comments on commit 21ade8f

Please sign in to comment.