I want to get total variants run for my Test Version 0
i.e Test Id=100
This is my table and records:
Test:
From top of my head, assuming I understood your confusing description. I think you need to union variants from both TestOperation
and TestOperationDifference
, then distinct and count them. Not sure if this will work in EF.
let toQuery = context.Test.SelectMany(mk=>TestOperation.Select(t=>t.SubVariants.Variants));
let todQuery = context.Test.SelectMany(mk=>TestOperationDifference.Select(t=>t.SubVariants.Variants));
let total = toQuery.Concat(todQuery).Disctinct().Count;
Also, your naming is confusing. You are using plural (s) for single-item references and you have SourceControlDetailId
in your model that is not in table and have SubVariants
and SubVariants1
instead of SourceSubVariant
and TargetSubVariant
. I would recommend to fix this first.
Update
Ok Learning, here it is a solution..
var tot_variants_for_test =
(from v_name in
(from t_op in test
select new { v_name = t_op.TestOperation.Select(sv => sv.SubVariants.Variants.Name) }
).First().v_name
select v_name)
.Union(
(from v_name in
(from t_opdf in test
select new { v_name = t_opdf.TestOperationDifference.Select(sv => sv.SubVariants.Variants.Name) }
).First().v_name
select v_name))
.Count();
from test in Tests
where version == 0
let opsVariants = test.TestOperations
.SelectMany(x => x.SourceSubVariant.Variant).Distinct()
let diffsVariants = test.TestOperationDifferences
.SelectMany(x => x.SourceSubVariant.Variant).Distinct()
let variants = opsVariants.Union(diffsVariants)
select variants.Count();