Skip to content

Instantly share code, notes, and snippets.

@afruzan
Created July 15, 2021 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afruzan/647c950f046a2cac5971ef02280eea66 to your computer and use it in GitHub Desktop.
Save afruzan/647c950f046a2cac5971ef02280eea66 to your computer and use it in GitHub Desktop.
// a query on db without any think on database data structure:
// (NullIfEmpty is my function on T[].)
var shardsBounds = context.Storages
.Select(i => new ShardBounds
{
StorageCode = i.StorageCode,
StartDateTime = i.StartDateTime,
EndDateTime = i.EndDateTime,
PlateReaderIds = i.StoragePlateReaders.Select(i => i.PlateReaderId).ToArray().NullIfEmpty(),
});
// continue with linq to object
// (the LeftJoin is my function on IEumerable<T>.)
var shards = someObjectsArray.LeftJoin(shardsBounds, i => i.StorageCode, i => i.StorageCode,
j => new ShardInfo<TContext>
{
ShardSettings = j.Outer,
Bounds = j.Inner
}).ToArray();
// translated query: a simple left join :)
/*
SELECT [s].[StorageCode], [s].[StartDateTime], [s].[EndDateTime], [s].[StorageId], [s0].[PlateReaderId], [s0].[StorageId]
FROM [Storages] AS [s]
LEFT JOIN [StoragePlateReaders] AS [s0] ON [s].[StorageId] = [s0].[StorageId]
ORDER BY [s].[StorageId], [s0].[StorageId], [s0].[PlateReaderId]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment