Results 1 to 2 of 2

Thread: [RESOLVED] codebehind on a domain service

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Location
    Burlington, ON, Canada
    Posts
    343

    Resolved [RESOLVED] codebehind on a domain service

    this post is a cut and paste from the vb.net forums that i posted a few days ago - i'm trying to figure out how to display as an integer the count of records returned from a query to a domain service - cut and paste is below:

    This post is somewhat of a hybrid as it involves vbcode directly but is being called from silverlight, so i thought i'd mention it here first.

    i'm trying to get an integer number from a query that reflects the count of rows returned.

    i have a domainservice called loginservice.vb containing the following:

    Code:
    Public Function GetLoginsByName(ByVal username As String, ByVal password As String) As IQueryable(Of login)
            Return Me.ObjectContext.logins.Where(Function(t) t.username = username AndAlso t.password = password)
        End Function
    and i have a mainpage.xaml.vb with a button on it that queries a database to see if there is a matching username and password - if the count is 0 i'd like to prompt the user that their credentials are no good, if the count is 1 (ie it found the user and password) then they can come in......

    here's the buttonclick code:

    Code:
    Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnLogin.Click
    
            Dim username As String = tbUserName.Text
            Dim password As String = pbPassword.Password
    
            Dim context = New LoginContext()
            context.GetLoginsByNameQuery(username, password).IncludeTotalCount = True
            DataGrid1.ItemsSource = context.logins
            context.Load(context.GetLoginsByNameQuery(username, password))
    
            Label3.Content = context.logins.EntityContainer.EntitySets.ElementAt(0).Count
    the datagrid is only there so that i could see the data was already being returned correctly....and it is - i just want to see if the query returns a result or if it does not.....

    i've looked at the includetotalcount items but no such luck.....any help would be appreciated.

    oh and label 3 is only for debugging so i can see if it will return 0 or 1....and in this case, always returns a 0 even if it finds a match in the table, so clearly i'm trying to get the count the wrong way, i'm just not sure what the syntax is for the right way.

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Location
    Burlington, ON, Canada
    Posts
    343

    Re: codebehind on a domain service

    figured it out, was an interesting ride going from winforms to silverlight....bit of a learning curve....heheheh - solution is here:

    http://www.vbforums.com/showthread.php?t=620770

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width