Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Select to a temporary cursor
Message
De
05/12/2008 00:56:26
 
 
À
04/12/2008 21:12:31
John Baird
Coatesville, Pennsylvanie, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01365559
Message ID:
01365591
Vues:
13
Hi John,

I haven't played around with LINQ much at all, so I have a question for you. In the following lines of code:
DataTable orders = ds.Tables["SalesOrderHeader"];

var ordersQuery = orders.ToQueryable();
where does "ToQueryable()" come from? I checked the documentation and didn't see that method associated with a DataTable, as you're using it. Perhaps that's part of Kevin's extension method, but I don't see it in the code you posted either. Did I miss something or did you leave out some of the code? Do you have a link to the article or blog where Kevin posted this?

Thanks!
~~Bonnie



>>Hi.
>>Is there a way in .net (C#) to select to a temporary Cursor and then use this as the source
>> of another select e.g.
>>
>>Select * ,.....from Tablea Into Table Temp1
>>Select * from Temp1 into Table Temp2
>>Select * from Temp2 into table Temp3...etc
>>
>>The above selects are just examples
>>Each select is more complicated , with numerous fields and some
>> of the selects are done for grouping purposes.
>>
>>Any help appreciated.
>>regards,
>>Gerard
>
>
>Hi Gerard,
>
>I believe you can do what you want using LinQ to DataSets.
>
>use LinQ to datasets to issue your select from datatable 1 into your var object.
>convert var object to a datatable
>
>each subsequent select and convert takes you back to another datatable.. until you reach the end of the chain.
>
>
>Kevin Goff published some excellent code as an extension method to converst the anonymous type "var" result to a datatable for you.
>
>
>// Take the anonymous type result "NewResult" and convert it to a DataTable
>
>DataTable dtResults = NewResult.ToADOTable( rec => new object[] {NewResult});
>
>
>public static class VarToTable
>{
>   public static DataTable ToADOTable<T>(
>      this IEnumerable<T> varlist, CreateRowDelegate<T> fn)
>   {
>      DataTable dtReturn = new DataTable();
>      // Could add a check to verify that there is an element 0
>      T TopRec = varlist.ElementAt(0);
>
>      // Use reflection to get property names, to create table
>      // column names
>      PropertyInfo[] oProps = ((Type)TopRec.GetType()).GetProperties();
>      foreach (PropertyInfo pi in oProps)
>         dtReturn.Columns.Add(pi.Name, pi.PropertyType);
>      foreach (T rec in varlist)
>      {
>         DataRow dr = dtReturn.NewRow();
>         foreach (PropertyInfo pi in oProps)
>            dr[pi.Name] = pi.GetValue(rec, null);
>         dtReturn.Rows.Add(dr);
>      }
>      return (dtReturn);
>   }
>   public delegate object[] CreateRowDelegate<T>(T t);
>}
>
>
>
>
>So putting it all together:
>
>
>
>DataTable orders = ds.Tables["SalesOrderHeader"];
>
>var ordersQuery = orders.ToQueryable();
>
>var query = from o in ordersQuery
>	    where o.Field<bool>("OnlineOrderFlag") == true
>            select new { SalesOrderID = o.Field<int>("SalesOrderID"), OrderDate = o.Field<DateTime>("OrderDate") };
>
>dtResults = query.ToADOTable( rec => new object[] {query});
>
>
>Now dtResults is a table that can be queried from as in the example above.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform