C# 为什么可以';是否重新排列此linq to sql对象的集合属性?

C# 为什么可以';是否重新排列此linq to sql对象的集合属性?,c#,linq,linq-to-sql,C#,Linq,Linq To Sql,我有一个linq到sql语句,如下所示: StreamEntry se = GenesisRepository.StreamEntry.FirstOrDefault( x => x.seID = 1); if ( se.FieldInstance != null) { se.FieldInstance = se.FieldInstance.OrderBy(x => x.fiOrder); } 然后,我尝试对一些关联的表行重新排序,如下所示: StreamEntry se

我有一个linq到sql语句,如下所示:

StreamEntry se = GenesisRepository.StreamEntry.FirstOrDefault( x => x.seID = 1);
if ( se.FieldInstance != null)
{
    se.FieldInstance = se.FieldInstance.OrderBy(x => x.fiOrder);
}
然后,我尝试对一些关联的表行重新排序,如下所示:

StreamEntry se = GenesisRepository.StreamEntry.FirstOrDefault( x => x.seID = 1);
if ( se.FieldInstance != null)
{
    se.FieldInstance = se.FieldInstance.OrderBy(x => x.fiOrder);
}
不幸的是,这给了我一个编译器错误:

Cannot implicitly convert type
'System.Linq.IOrderedEnumerable<Genesis.Domain.Entities.FieldInstance>'
to 'System.Data.Linq.EntitySet<Genesis.Domain.Entities.FieldInstance>'
无法隐式转换类型
'System.Linq.IOrderedEnumerable'
至“System.Data.Linq.EntitySet”

我如何才能做到这一点?

您无法将查询重新分配回se.Fieldnstance,因为它的类型错误。更改类型或将查询存储在其他位置:

IOrderedEnumerable<Genesis.Domain.Entities.FieldInstance> fieldInstance = null;
if ( se.FieldInstance != null)
{
    fieldInstance = se.FieldInstance.OrderBy(x => x.fiOrder);
}
IOrderedEnumerable fieldInstance=null;
如果(se.FieldInstance!=null)
{
fieldInstance=se.fieldInstance.OrderBy(x=>x.fiOrder);
}

无法将查询重新分配回se.Fieldnstance,因为它的类型错误。更改类型或将查询存储在其他位置:

IOrderedEnumerable<Genesis.Domain.Entities.FieldInstance> fieldInstance = null;
if ( se.FieldInstance != null)
{
    fieldInstance = se.FieldInstance.OrderBy(x => x.fiOrder);
}
IOrderedEnumerable fieldInstance=null;
如果(se.FieldInstance!=null)
{
fieldInstance=se.fieldInstance.OrderBy(x=>x.fiOrder);
}

要将其转换回EntitySet,请查看本文的回复


要将其转换回EntitySet,请查看本文的回复


@Gabe-谢谢你的问题编辑。这更清楚了。@Gabe-谢谢你的问题编辑。这更清楚了。你知道我将如何更改查询类型吗?我非常希望将
FieldInstance
集合保留在se.FieldInstance中。您知道我将如何更改查询类型吗?我非常希望将
FieldInstance
集合保存在se.FieldInstance中。