API
Version 7.x > API > InfoDataSet => Linq Select View modes: 
User avatar
Certified Developer 11
Certified Developer 11
jellison - 6/25/2013 3:34:04 PM
   
InfoDataSet => Linq Select
Linq Select doesn't seem to be available for InfoDataSets:
InfoDataSet<ForumGroupInfo> forumGroups = ForumGroupInfoProvider.GetGroups(forumGroupWhere, "");

var forumGroupIds = (from fgId in forumGroups
select fgId.GroupID);

I know there are a few other ways to convert it, but I thought that InfoDataSets were Inumerable. I'm just wondering what is the optimal way to accomplish this.

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 7/3/2013 3:21:27 AM
   
RE:InfoDataSet => Linq Select
Hi,

What is the exact issue? Any compilation or runtime error?
Could you please provide us with more context where are you using this code?
I believe it should work but I think I am missing some more info.

Thank you!

Best regards,
Juraj Ondrus

User avatar
Certified Developer 11
Certified Developer 11
jellison - 7/10/2013 4:50:34 PM
   
RE:InfoDataSet => Linq Select
Thanks for the replies.

@Juraj
Trying to do what I wrote in my last post resulted in a compile time error. Then I tried:

InfoDataSet<ForumGroupInfo> forumGroups = ForumGroupInfoProvider.GetGroups(forumGroupWhere, "");
var forumGroupIds = (from fgId in forumGroups.Items.Cast<ForumGroupInfo>()
select fgId.GroupID);

...which always resulted in an empty list. I was just wondering if there was a better way than what I've posted below.

@Swainy - I did have that initially (it does work), but I didn't like losing the property information for what I was doing.

I ended up doing:
InfoDataSet<ForumGroupInfo> forumGroups = ForumGroupInfoProvider.GetGroups(forumGroupWhere, "");
var forumGroupIds = (from fgId in forumGroups.Items.ToList<ForumGroupInfo>()
select fgId.GroupID);

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 7/11/2013 8:11:25 AM
   
RE:InfoDataSet => Linq Select
Hi,

The only idea I have at this moment is to use something like this, define the type for the fgId:

from ForumGroupInfo fgId in forumGroups ...


Best regards,
Juraj Ondrus

User avatar
Certified Developer 11
Certified Developer 11
jellison - 7/18/2013 12:08:34 PM
   
RE:InfoDataSet => Linq Select
Thanks Juraj! That did work. I ended up with:

InfoDataSet<ForumGroupInfo> forumGroups = ForumGroupInfoProvider.GetGroups(forumGroupWhere, "");
var forumGroupIds = (from ForumGroupInfo forumGroup in forumGroups
select forumGroup.GroupID);

User avatar
Member
Member
Swainy - 7/4/2013 5:19:44 AM
   
RE:InfoDataSet => Linq Select
Hi,

I think you can do this but it's not the infodataset that's enumerable it's the table...

Can you try this logic, which whould hopefully work...
var forumGroupIds = (from fgId in forumGroups.Tables[0].AsEnumerable()
select fgId.Field<int>("GroupID"));