Why can't I reorder collection properties of this linq to sql object?
I have a linq to sql statement like this:
StreamEntry se = GenesisRepository.StreamEntry.FirstOrDefault( x => x.seID = 1);
I then tried to reorder some of the associated table rows like this:
if ( se.FieldInstance != null)
{
se.FieldInstance = se.FieldInstance.OrderBy(x => x.fiOrder);
}
Unfortunately, this gives me a compiler error:
Cannot implicitly convert type
'System.Linq.IOrderedEnumera开发者_高级运维ble<Genesis.Domain.Entities.FieldInstance>'
to 'System.Data.Linq.EntitySet<Genesis.Domain.Entities.FieldInstance>'
How could I accomplish this?
You can't reassign your query back to se.Fieldnstance because it has the wrong type. Either change the type, or store your query elsewhere:
IOrderedEnumerable<Genesis.Domain.Entities.FieldInstance> fieldInstance = null;
if ( se.FieldInstance != null)
{
fieldInstance = se.FieldInstance.OrderBy(x => x.fiOrder);
}
To convert it back to an EntitySet have a look at the responses on this post.
http://social.msdn.microsoft.com/Forums/en/linqprojectgeneral/thread/58c4dcf8-2d89-4a3c-bb30-58c7c15df04b
精彩评论