Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Returning record versus fields only
Message
De
10/04/2012 11:00:35
 
 
À
10/04/2012 10:40:44
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01540661
Message ID:
01540814
Vues:
20
>>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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform