开发者

Why can't I reorder collection properties of this linq to sql object?

开发者 https://www.devze.com 2023-01-31 01:58 出处:网络
I have a linq to sql statement like this: StreamEntry se = GenesisRepository.StreamEntry.FirstOrDefault( x => x.seID = 1);

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

0

精彩评论

暂无评论...
验证码 换一张
取 消