本文介绍了如何通过组2子实体,并得到双方总这个孩子实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得的总变种运行我的测试版本0 测试ID = 100

这是我的表和记录:

测试:

  ID版本
100 0

变体:

  ID名称类型的CategoryId
11 VARIANT1 DIFF 2
12 VARIANT1添加2
13 VARIANT2添加3
14 VARIANT2 DIFF 2
15 VARIANT3添加6

SubVariants

 标识VariantId名称
66 11美国广播公司
67 11 PQR
68 11 XYZ69 12美国广播公司
70 12 PQR
71 12 XYZ72 13美国广播公司
73 13 PQR74 14美国广播公司
75 14 PQR
76 14 XYZ77 15 ABC
78 15 PQR

TestOperation

 标识TestId SourceSubVariantId TargetSubVariantId变化
1 100 69 70 0
1 100 70 71 20
1 100 72 73 90

TestOperationDifference:

 标识TestId SourceSubVariantId TargetSubVariantId UNMATCH
1 100 66 67 0
1 100 67 68 2
1 100 74 75 7
1 100 75 76 0
1 100 77 78 26

因此​​,从上面记载有共有3个变种 2 类型的操作即<$ C $运行C> TestOperation 和 TestOperationDifference 以下是具体的3个变种测试100

  Variants1(此运行在TestOperation)
Variants2(此运行在TestOperation)
Variants3(此运行在TestOperationDifference)

由于这一切的父子变种在2个表即 TestOperation和TestOperationDifference使用上面这3父变种会来的。

所以,寻找总父变种我需要从两个表(TestOperation和TestOperationDifference)计算出的使用和基于相应的子变种上,我需要算总父变种

这是我的类:

 公共类测试
        {
            公众诠释标识{搞定;组; }
            公共字符串版本{搞定;组; }
            公共虚拟的ICollection&LT; TestOperation&GT; TestOperation {搞定;组; }
            公共虚拟的ICollection&LT; TestOperationDifference&GT; TestOperationDifference {搞定;组; }
        }        公共类TestOperation
        {
            公众诠释标识{搞定;组; }
            公众可空&LT; INT&GT; TestId {搞定;组; }
            公众诠释SourceSubVariantId {搞定;组; }
            公众诠释TargetSubVariantId {搞定;组; }
            公众诠释的变化{搞定;组; }
            公共虚拟SubVariants SubVariants {搞定;组; }
            公共虚拟SubVariants SubVariants1 {搞定;组; }
            公共虚拟测试测试{搞定;组; }        }        公共类TestOperationDifference
        {
            公众诠释标识{搞定;组; }
            公众可空&LT; INT&GT; TestId {搞定;组; }
            公众诠释SourceSubVariantId {搞定;组; }
            公众诠释TargetSubVariantId {搞定;组; }            公众诠释UNMATCH {搞定;组; }            公共虚拟SubVariants SubVariants {搞定;组; }
            公共虚拟SubVariants SubVariants1 {搞定;组; }
            公共虚拟测试测试{搞定;组; }
        }        公共类变体
        {
            公众诠释标识{搞定;组; }
            公共字符串名称{;组; }
            公共字符串类型{搞定;组; }
            公众诠释的CategoryId {搞定;组; }            公共虚拟的ICollection&LT; SubVariants&GT; SubVariants {搞定;组; }            公共虚拟分类分类{搞定;组; }
        }        公共类SubVariants
        {
            公众诠释标识{搞定;组; }
            公众诠释VariantId {搞定;组; }
            公共字符串名称{;组; }            公共虚拟变种变种{搞定;组; }
            公共虚拟的ICollection&LT; TestOperationDifference&GT; TestOperationDifference {搞定;组; }            公共虚拟的ICollection&LT; TestOperationDifference&GT; TestOperationDifference1 {搞定;组; }
            公共虚拟的ICollection&LT; TestOperation&GT; TestOperation {搞定;组; }
            公共虚拟的ICollection&LT; TestOperation&GT; TestOperation1 {搞定;组; }
        }

我的查询:

  =(从MK在context.Test VAR数据
                  新选择
                  {                      TotalVariants =(mk.TestOperation.Select(T =&GT; t.SubVariants).Count之间的()
                                   +
                                      mk.TestOperationDifference.Select(T =&GT; t.SubVariants).Count之间的())
                    })了ToList()。

Can anybody help me with this???

Sorry if question seems to be so big.

解决方案

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();

这篇关于如何通过组2子实体,并得到双方总这个孩子实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-25 09:59