Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
LINQ -- some questions
Message
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
LINQ -- some questions
Divers
Thread ID:
01272580
Message ID:
01272580
Vues:
77
Hey all,

Finally got the VS 2008 Beta installed at work and have been playing with LINQ. Intriguing stuff. As a Foxpro fanatic, I naturally wanted to play first with what Foxpro does well -- joining disparate data sources locally.

So, I gatheered some data from SQL Server (into an ADO.NET DataTable) and some from a DBF (gathered also into an ADO.NET DataTable). Then I started slicing it up: filtering, joining, re-filtering... here is my code:
// Start with a simple filter on a single data source...
var qryDebtorIL = from Debtor in dtDebtor.AsEnumerable()
                  where Debtor.Field<string>("state").Trim() == "IL"
                  select Debtor;
// Now let's do a join on HD and DEBTOR information.
var qryJoin = from HD in dtHD.AsEnumerable()
              join Debtor in qryDebtorIL on HD.Field<string>("file_num").Trim() equals Debtor.Field<string>("file_num").Trim()
              select Debtor;
qryDebtorIL is simple, just a filter on my dtDebtor DataTable, getting the list down to only IL debtors.

qryJoin joins the debtor query to a parent DataTable, dtHD. They join on a field called "file_num", and I keep just the "Debtor" entity. That allows the result to still be an Enumerable of DataRows (making it easier to get into a grid, for example).

My first question is this: in the second query, how would I get everything from Debtor _and_ HD? In other words, what is the LINQ equivalent for:
SELECT HD.*, Debtor.* FROM HD INNER JOIN Debtor ;
    ON HD.file_num = DEBTOR.file_num
I know I can manually make my LINQ "select" designate specific fields (using Field), but that brings me to a second question/gripe: In LINQ, any time one makes the "select" result be something explicitly named (like plucking out specific fields), the resulting Enumerable is no longer a set of DataRows when enumerated. And there does not appear to be any easy conversion method. That sucks. Tons of Visual Studio controls tap into standard ADO.NET data classes. If the wonderful world of LINQ always results in an unusuable object list (I do not want to have to "foreach" myself blue in the face every time I want to present a result), then what's the point? How does one keep complex LINQ statements in the realm of DataRows?

Can anyone help a newbie make LINQ sing like my glorious Foxpro cursors? *smile* Any and all help is greatly appreciated!

Thanks,
JoeK
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform