Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
LINQ to datatable - how to create a variable?
Message
De
02/07/2013 09:02:40
John Baird
Coatesville, Pennsylvanie, États-Unis
 
 
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:
01576896
Message ID:
01577623
Vues:
69
This message has been marked as a message which has helped to the initial question of the thread.
>>>I am now trying to declare a variable with anonymous type and I can not figure out how to declare this variable correctly. The showed declaration doesn't help me
>>>
>>>
>>>var query = dtBookings.AsEnumerable().Select(c => new
>>>    {
>>>       booking_id = c.Field<Decimal>("booking_id"),
>>>       lname = c.Field<String>("lname"),
>>>       start_time = c.Field<DateTime?>("start_time"),
>>>       end_time = c.Field<DateTime?>("end_time"),
>>>       flex_tspan = c.Field<Boolean>("flex_tspan"),
>>>       layer = c.Field<Byte>("layer"),
>>>       backcolor = c.Field<Int32>("backcolor"),
>>>       forecolor = c.Field<Int32>("forecolor"),
>>>       clip_loc = c.Field<Boolean>("clip_loc"),
>>>       clip_sp = c.Field<String>("clip_sp"),
>>>       display_msg = "#Slots: " + c.Field<Int16>("num_addit").ToString() + " " + c.Field<String>("display_msg"),
>>>       isnotes = c.Field<Boolean>("isnotes"),
>>>       bookingType = "POD"
>>>    });
>>
>>and the problem is?
>
>The problem is to declare query variable separately and re-use it later.
>
>However, I decided to change that approach completely and just use stored procedure. So, for now I don't need this variable. However, I still would be interested to know as how to properly define the query variable.


I don't think you can. I rarely use anon types because of the restrictions on their usage. I generally just create a class definition like the anyonymous fields I want and then fill that class instead of an anon type. That way I can pass it around as a parameter if need be.

Did a quick google on anonymous types in c# and found this: "The type name cannot be specified in the variable declaration because only the compiler has access to the underlying name of the anonymous type.".
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform