如何保存子查询结果?

时间:2015-08-03 06:06:01

标签: linq entity-framework subquery entity-framework-6

我有这样的疑问:

var result = from tsr in db.tsr
where tsr.SomeId = x
where tsr.Sequence > ((from tsr2 in db.tsr where tsr2.SomeId = y where tsr2.FitId = tsr.FitId select tsr2.Sequence)).FirstOrDefault()
select new MyClass()
{
   Properties = tsr.properties // (simplicified)
}

我想知道如何在我的tsr2.Sequence对象中选择NewClass值?

1 个答案:

答案 0 :(得分:0)

select new MyClass(){

MyClass.Property1 = tsr.Sequence.PropertyX,
MyClass.Property2 = tsr.Sequence.PropertyY,
MyClass.Property3 = tsr.Sequence.PropertyZ,
......
}

您可以逐个选择和分配属性。并确保您的MyClass对象属性是公共的