Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Returning record versus fields only
Message
From
09/04/2012 13:32:04
 
 
To
09/04/2012 10:18:42
General information
Forum:
ASP.NET
Category:
LINQ
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01540661
Message ID:
01540695
Views:
50
>I need to understand something in regards to the way LINQ work went returning records versus only a few fields.
>
>I have a declaration like this:
>
>
>    Public oClient As ClientAPI.ClientService.Client = Nothing
>
>
>Then, I can do my SQL:
>
>
>                oClient = (From c
>                 In oGeneric.GetClients()
>                 Where c.Id = nClientID).FirstOrDefault()
>
>
>However, if I have to return only a few fields, I will adjust for something like this:
>
>
>                oClient = (From c
>                 In oGeneric.GetClients()
>                 Where c.Id = nClientID
>                 Select c.FirstName,cLastName).FirstOrDefault()
>
>
>This will then generate this design time error:
>
>"Value of type 'anonymous type (line 87)' cannot be converted to 'ClientAPI.ClientService.Client'."
>
>Obviously , the declaration is done in a way that it expects the record to be returned. So, when I try to select only a few fields, it does not like it.
>
>Can someone share some light on that?

The exeption says it all. You are requiring a return type of ClientAPI.ClientService.Client but the select is generating an anonymous type.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform