Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Returning record versus fields only
Message
From
10/04/2012 11:00:35
 
 
To
10/04/2012 10:40:44
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:
01540814
Views:
19
>>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.
>
>Thanks, but it seems all is OK with that. While the query will expose the other fields, they will be null. The goal here is to only have the FirstName and LastName to be transferred across the wire.

That won't be the case - but whether the overhead of also transferring the unused fields is acceptable will, I guess, depend on how many other fields there are and how the defaults are defined.....

As our application as the definition of those classes, it would then be normal the other fields will appear in the intellisense of oClient but only FirstName and LastName would be initialized.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform