Is there way to write multiple conditions of LINQ in single command in vb.net

Hakan
Hakan used Ask the Experts™
on
I've a below code to filtering my files but it's a bit hard way because i declare it in if end if loop and other variables which using it cannot seee it i wonder is there any possible way to simplify this;

Any help would be grateful. Thank you.

                If My.Settings.user_build__list_prt = False Then

                    Dim getHp = From group In subvarGroupList
                                Where group.fullName.EndsWith(My.Settings.str_elem__subvar_grpname_hp) AndAlso Path.GetFileNameWithoutExtension(group.origin).StartsWith("prt_") = My.Settings.user_build__list_prt
                                Select group
                Else
                    Dim getHp = From group In subvarGroupList
                                Where group.fullName.EndsWith(My.Settings.str_elem__subvar_grpname_hp)
                                Select group
                End If

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
NorieAnalyst Assistant

Commented:
Hakan

Not sure about doing it all in one command/statement but perhaps you could try it something like this.
Dim getHp = From group In subvarGroupList
            Where group.fullName.EndsWith(My.Settings.str_elem__subvar_grpname_hp)
            Select group

If My.Settings.user_build__list_prt = False Then
	getHp.Where(Path.GetFileNameWithoutExtension(group.origin).StartsWith("prt_") = My.Settings.user_build__list_prt)

Open in new window

That, to me anyway, makes things a little clearer.
Commented:
You could always declare your variable outside of the if block; e.g. -
Dim getHp As IEnumerable(Of Group)
If My.Settings.user_build__list_prt = False Then
    getHp = From group In subvarGroupList 
                   Where group.fullName.EndsWith(My.Settings.str_elem__subvar_grpname_hp) 
                   AndAlso Path.GetFileNameWithoutExtension(group.origin).StartsWith("prt_") = My.Settings.user_build__list_prt
                   Select group
Else
    getHp = From group In subvarGroupList 
                   Where group.fullName.EndsWith(My.Settings.str_elem__subvar_grpname_hp) 
                   Select group
End If

Open in new window

-saige-

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial