Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
What to do in this situation?
Message
 
 
À
01/08/2015 12:28:00
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01622794
Message ID:
01622831
Vues:
33
>>Hi everybody,
>>
>>We have a Web Application with a few layers to access and return data. In the repository we're normally doing queries and return an IEnumerable of the class or just one row of the class.
>>
>>I have a need to return just 2 columns back. I don't want to define a new class. What do you normally do in this situation? E.g. how do you define a method to return a new object without creating a new class? Do you use just object in the signature?
>
>Not enough info about your layers but, in general, I *would* create a new class for the two fields - but farther down the hierarchy and not at the repository level.
>You can then retrieve the full rows and use Linq to select into the smaller class. e.g:
var shortRecords = fullRecords.Select(x => new ShortRecord {Age = x.Age, Name = x.Name});
Returning an object jeopardizes type safety and can quickly become messy.....

Where would you create this class - at the model level?

E.g. we have Data, Model, Repository, Adapter and the API controller. I need to return it back to APIController through repository and adapter.

Thanks again, I'll go the class route then rather than returning an object.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform