Jul 5th, 2010, 05:49 PM
[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:
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......
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)
here's the buttonclick code:
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.....
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
Label3.Content = context.logins.EntityContainer.EntitySets.ElementAt(0).Count
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.
Jul 8th, 2010, 03:14 PM
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:
Click Here to Expand Forum to Full Width
Survey posted by VBForums.