我的表中有以下记录:
变体:
Id RegionId Type Name
1 1001 Add A1
2 1001 Diff A2
3 1001 Mul A3
4 1001 Diff A4
5 1001 Mul A5
VariantsinTest :在测试中存储变体
Id TestId VariantId
1 1 5
2 1 4
3 1 3
4 1 2
5 1 1
6 2 5
7 2 3
8 2 1
9 3 4
10 3 3
11 3 2
12 3 1
测试
Id RegionId Name Run
1 1001 T1 True
2 1001 T2 True
3 1001 T3 True
的DataModel:
public partial class Test
{
public int Id { get; set; }
public string Name { get; set; }
public bool Run { get; set; }
public Nullable<int> RegionId { get; set; }
public virtual ICollection<VariantsinTest> VariantsinTest { get; set; }
public virtual Region Region { get; set; }
}
public partial class VariantsinTest
{
public int Id { get; set; }
public int TestId { get; set; }
public int VariantId { get; set; }
public virtual Variant Variant{ get; set; }
public virtual Test Test { get; set; }
}
public partial class Variant
{
public int Id { get; set; }
public int RegionId { get; set; }
public string Type { get; set; }
public string Name { get; set; }
public virtual Region Region { get; set; }
public virtual ICollection<VariantsinTest> VariantsinTest { get; set; }
}
现在我试图仅针对特定区域获取测试列表,并且仅通过跳过最后2个最新测试并获取所有其他测试,将Run值变为True,但是问题在于上面的测试记录我没有得到记录测试ID = 1 。
查询:
var data = (from t in context.Test
where t.Run == True &&
(t.RegionId == 1001 )
&& t.VariantTest.Any(vt => vt.Variant.Type == "Diff")) // get test list for diff type only
orderby t.Id descending
select new
{
Id = t.Id,
name = t.Name
}).Skip(2).ToList();
通过上述查询,我没有得到第一次测试的记录。