Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Returning record versus fields only
Message
De
10/04/2012 09:50:04
 
 
À
10/04/2012 09:13:56
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:
01540802
Vues:
29
>>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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform