Created
July 15, 2021 13:32
-
-
Save afruzan/647c950f046a2cac5971ef02280eea66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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