Quantcast
Viewing all articles
Browse latest Browse all 256

Selecting First element with IQueryable

Hi Guys,
I am working on a Windows Phone Contacts app and I am trying to make a query of the first IEnumerable element in the variable "contacts".
The output has to be shown in the Listbox under the variable "firstperson".
Currently the output returns all elements even when I added .First() after the firstperson variabele.

Hope you guys can help me out!

Here is my code:

Code:

Imports System
Imports System.Threading
Imports System.Windows.Controls
Imports Microsoft.Phone.Controls
Imports Microsoft.Phone.Shell
Imports System.IO
Imports System.Xml.Serialization
Imports System.Linq
Imports System.Xml.Linq

Partial Public Class MainPage
    Inherits PhoneApplicationPage

    ' Constructor
    Public Sub New()
        InitializeComponent()

        SupportedOrientations = SupportedPageOrientation.Portrait Or SupportedPageOrientation.Landscape

        'Uitlezen en sorteren elementen op "Voornaam" Contacten.xml
        Dim document = XDocument.Load("Assets\Contacten.xml")
        Dim element As XElement = XElement.Load("Assets\Contacten.xml", LoadOptions.None)
        Dim elementSorted As XElement() = element.Elements("Persoon").OrderBy(Function(t) CStr(t.Element("Voornaam"))).ToArray()

        Dim contacts = elementSorted.[Select](Function(t) New Contact() With {
            .Achternaam = t.Element("Achternaam").Value,
            .Voornaam = t.Element("Voornaam").Value,
            .Emailadres = t.Element("Emailadres").Value
        })

        Dim firstperson As IQueryable(Of Contact) = contacts.AsQueryable().Where(Function(person) person.Voornaam.Any())
        firstperson.First()

        ContactListBox.DataContext = firstperson

    End Sub


    Public Class Contact

        <XmlElement("Achternaam")>
        Public Property Achternaam As String

        <XmlElement("Voornaam")>
        Public Property Voornaam() As String

        <XmlElement("Emailadres")>
        Public Property Emailadres() As String

        <XmlElement("Geboortedatum")>
        Public Property Geboortedatum() As String

        <XmlElement("Telefoon")>
        Public Property Telefoon() As String

        <XmlElement("Fotobestand")>
        Public Property Fotobestand() As String

        <XmlElement("Fotolink")>
        Public Property Fotolink() As String



    End Class

End Class


Viewing all articles
Browse latest Browse all 256

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>