Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Returning record versus fields only
Message
From
10/04/2012 09:50:04
 
 
To
10/04/2012 09:13:56
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:
01540802
Views:
28
>>Not sure I understand. You are still creating an instance of ClientAPI.ClientService.Client and all of its fields will be present. The only difference is that everything other than FirstName and LastName will have default values.
>
>Well, the foreign provider wants us to adjust those Linq queries to collect only the required fields and not returning the entire record. Does this mean I have more adjustment to do here?
>
>As if this returns the entire record, but empty values for the other fields, I am not better than before. lol

Best solution would depend on what you need to do with the simple FirstName/LastName structure. You could create a new class with just the FirstName/LastName fields and then
Private shortClient As ShortClientInfo = GetClients.Where(Function(x) x.Id = id).[Select](Function(s) New ShortClientInfo() With { _
	Key .LastName = s.LastName, _
	Key .FirstName = s.FirstName _
}).FirstOrDefault()
(Hope the VB's OK - used a converter from C# :-{ )
But if you do *not* need to access this outside of the method where the selection is made you could just use an anonymous type:
Dim shortClient = GetClients.Where(Function(x) x.Id = id).[Select](Function(x) New With { _
	Key .LastName = x.LastName, _
	Key .FirstName = x.FirstName _
}).FirstOrDefault()
shortClient.LastName, shortClient.FirstName will be valid within the scope of the linq statement.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform