HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpMinor

Fetching a set of event IDs from a database based on a set of company IDs

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
companyidsdatabasebasedfetchingfromsetevent

Problem

The following code fetches a set of company IDs from a database if there are any events associated with a company that has a missing property. Because the set of company IDs is embedded into the SQL query using parameters, and the number of parameters may exceed the maximum for the RDBMS / database driver, the set is partitioned into maximal subsets.

Performance aside, in terms of maintainability and ability to debug, is the following "too Linq-y"?

HashSet missingCompanyIds =
    companyEvents
        .Select(ev => ev.CompanyId).ToHashSet()
        .Partition(DataContext.MaxAvailableSqlParameters(usedParameters), true)
        .SelectMany(companyIdsPartition =>
                missingEventsQuery                                           // linq-to-sql
                    .Where(ev => companyIdsPartition.Contains(ev.CompanyId)) // linq-to-sql
                    .Select(ev => ev.CompanyId)                              // linq-to-sql
                    .Distinct())                                             // linq-to-sql
        .ToHashSet();


If any of the database side-effects of the query methods cause a crash, perhaps this is harder to debug, I don't know. I am able to set breakpoints inside lambdas, but my local environment might contain fewer of the objects I wish to inspect when debugging (e.g. the missingEventsQuery)? I'm unsure if these concerns would be relevant in practice.

Would there be any advantages in the case above if some of the .Select()s were written as for loops?

Solution

Not so a direct answer to your question but this may help you.

Most of methods you are using are really extension methods, If your only worry is debugging or logging, you can get code for these methods and create your own extension methods with same names but Namespace must be different.

As these are extension methods, you will not be able to override them.

Context

StackExchange Code Review Q#111210, answer score: 3

Revisions (0)

No revisions yet.