How to setup a variable for LINQ usage

D

Don Juan

Hi all
I have this:

Dim var1 = From Personal In db1.Data _
Select Personal.Name

Works fine, but I need just declarate de variable in order to put this in IF
or Case structures, something like this:

Dim var1 AS (DataType)
If x=1 then
var1 =From Personal In db1.Data _
Select Personal.Name
Else
var1 =From Personal In db1.DataOld _
Select Personal.Name
End If

Thanks in advanced.
 
A

Anthony Jones

Don Juan said:
Hi all
I have this:

Dim var1 = From Personal In db1.Data _
Select Personal.Name

Works fine, but I need just declarate de variable in order to put this in
IF or Case structures, something like this:

Dim var1 AS (DataType)
If x=1 then
var1 =From Personal In db1.Data _
Select Personal.Name
Else
var1 =From Personal In db1.DataOld _
Select Personal.Name
End If

Assuming name is a String:-

Dim var1 As IEnumerable(Of String)
 
D

Don Juan

Thanks, but if I need more that one field???
I have this:

Dim var1 = From Personal In db1.Data _
Select Personal.Name, Personal.SurName
Text1.text = var1.FirstOrDefault.SurName

If I declare
Dim var1 As IEnumerable(Of String)
I lost the FirstOrDefault function

IfI declare
Dim var1 As IQueryable(Of String)
I can't take the .Name or .SurName fields, but I have the FirstOdDefault
function

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top