Link to home
Start Free TrialLog in
Avatar of Neogeta
NeogetaFlag for United Kingdom of Great Britain and Northern Ireland

asked on

WCF Rest / Linq

Hello,

I'm working on a WCF Service based off the WCF Rest 4.0 template and help from you guys.
The service will be to return unmarked registers with student details and photo.

I am now stuck linq isn't quite behaving how it does within linqpad.

I have three tables; a staff table, a register table and a student table. A register can have one member of staff and more than one student. so for staffid 1 I'm expecting 5 rows.
My linqpad query returns 5 rows, my vb code returns one line, and I have no idea whats wrong

Any help would be greatly appreciated.
Thanks
David  
Public Function GetStaffRegister(ByVal id As String) As List(Of Register)
            Dim dc As New RegistersEntities3
            Dim P =
                From r In dc.Registers _
            Where r.staffid = id
            Return P.ToList
        End Function

Open in new window

Avatar of VincentSG
VincentSG
Flag of Singapore image

Hi!

Your Linq code seems to be correct.

Just few questions/ guesses::
1) Why are you stating your id as String? Perhaps you want to try setting it as Int?
2) How is the result returned to you different from the other 4 that are not returned?

Avatar of Neogeta

ASKER

Thanks for the reply.
1)
It looks like I missed off the top line of that function when I pasted it, I don't know if it makes a difference.
When I change the id to an integer I get this error message:
Exception Details: System.InvalidOperationException: Operation 'GetStaffRegister' in contract 'RegisterTask' has a path variable named 'id' which does not have type 'string'.  Variables for UriTemplate path segments must have type 'string'.
2)
From what I can see, its only displaying the first item.
After looking at the XML output again when looking at the end of the XML it's displaying 4 register references.
I've attached the XML and Results I was expecting, I'm sorry for not doing so from the start.
<WebGet(UriTemplate:="Staff/Reg/{id}")>
Public Function GetStaffRegister(ByVal id As String) As List(Of Register)
            Dim dc As New RegistersEntities3
            Dim P =
                From r In dc.Registers _
            Where r.staffid = id
            Return P.ToList
        End Function

Open in new window

1.xml
linqresult.JPG
ASKER CERTIFIED SOLUTION
Avatar of VincentSG
VincentSG
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Neogeta

ASKER

Thank you!
I've added a student/register id and everything seems better.
Well one of the records has two events, but that's down to my poor database structure.

The problem was that I'm using a much more cut down set of data than I normally would be working with. I havnt got all the tables/linkages that I would normally have.

Thank you for the help