Skip to content

Instantly share code, notes, and snippets.

@joonhwan
Created October 25, 2018 00:50
Show Gist options
  • Save joonhwan/1e3c1a016a8317949229ca0ca41f7c6e to your computer and use it in GitHub Desktop.
Save joonhwan/1e3c1a016a8317949229ca0ca41f7c6e to your computer and use it in GitHub Desktop.
Hiearchy를 가지는 Composite Key에 대해 계층을 만드는 LINQ예
public class SeqKeyRepository
{
public Dictionary<long, Dictionary<long, Dictionary<long, Dictionary<long, HashSet<long>>>>> FindHierachies()
{
return FindAll()
.GroupBy(key => key.DeviceId)
.ToDictionary(deviceGroup => deviceGroup.Key, deviceGroup =>
{
return deviceGroup
.GroupBy(key => key.SeqId)
.ToDictionary(stepGroup => stepGroup.Key, stepGroup =>
{
return stepGroup
.GroupBy(key => key.RecipeId)
.ToDictionary(recipeGroup => recipeGroup.Key, recipeGroup =>
{
return recipeGroup
.GroupBy(key => key.ModelId)
.ToDictionary(modelGroup => modelGroup.Key, modelGroup =>
{
return new HashSet<long>(modelGroup.Select(key => key.SeqId));
})
;
});
});
})
;
}
public IEnumerable<SeqKey> FindAll()
{
return OpticaDb.Instance
.Query<SeqKey>("select DEVICE_ID as DeviceId, STEP_ID as StepId, RECIPE_ID as RecipeId, MODEL_ID as ModelId, SEQ_ID as SeqId from SIM_RESULT");
}
}
public class SeqKey
{
public long DeviceId { get; set; }
public long StepId { get; set; }
public long RecipeId { get; set; }
public long ModelId { get; set; }
public long SeqId { get;set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment