How to setup a variable for LINQ usage

  • Thread starter Thread starter Don Juan
  • Start date Start date
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.
 
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)
 
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
 
Back
Top