Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Iterate over columns in LINQ to SQL result
Message
 
À
18/11/2008 09:39:40
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP SP2
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01362512
Message ID:
01362530
Vues:
8
Craig,

Thank you for your suggestions. I got a reply on the MSDN forum that looks like it will work for me. The answer is to use the Reflection namespace as follows, this is great:
using System.Reflection;  
...  

BindingFlags b = BindingFlags.Instance | BindingFlags.Public  
var myProps = typeof(CSVTest).GetProperties(b)  
 
foreach (CSVTest tst in _CSVTests)  
{  
    foreach(var p in myProps )  
    {  
        object x = p.GetGetMethod().Invoke(tst, null);  
        //Do stuff with x and p.Name  
    }  
} 
>I don't think you can iterate through the columns like you want using LINQ. If you want to do that you'll need to use datasets.
>
>>Craig,
>>
>>I wasn't clear enough in my fist question. My first foreach loop works Ok, as does yours. What I really want is an inner foreach loop to step through the columns, something similar to:
>>
>>
>>
>>var _CSVTests = from cs in db.CSVTests
>>                               select cs;
>>
>>foreach (CSVTest tst in _CSVTests)
>>{
>>       foreach (Column c in tst)
>>           {
>>                 Do something with the value of each column if it isn't null.
>>           }
>>}
>>
>>
>>
>>I know the "foreach (Column c in tst) " part is not proper. What is?
>>
>>How do I get a collection of columns for each "record" in my _CSVTests ?
>>
>>Thanks.
>>
Elgin Rogers
Epic Solutions
www.epicsolutions.net
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform