Skip to main content

Posts

Showing posts from March, 2009

LINQ to SQL Roundtrips: SQL Trace

I was looking into reducing the number of database round trips that LINQ to SQL took and found an article by David Hayden that fit the bill. I wanted to see what was actually happening so I slapped together a simple demo. Using the Pubs database I created a console app, added the LINQ to SQL classes then created a simple repository class: public class AuthorRepository { public author GetAuthorWithTitles( string authorId) { var db = new PubsDataClassesDataContext (); return db.authors.FirstOrDefault(a => a.au_id == authorId); } public author GetAuthorWithTitlesWithUsing( string authorId) { using ( var db = new PubsDataClassesDataContext ()) return db.authors.FirstOrDefault(a => a.au_id == authorId); } public author GetAuthorWithTitlesPrefecth( string authorId) { using ( var db = new PubsDataClassesDataContext ()) { var options = new DataLoadOptions (); op

DataTable: Finding Differences in Column Values

I have two tables in a typed DataSet and I want to compare one column in each table to see if TableA has values that are not in TableB. IEnumerable < string > valuesInA = typedDataSet.TableA.AsEnumerable().Select(row => row.AField); IEnumerable < string > valuesInB = typedDataSet.TableB.AsEnumerable().Select(row => row.BField);   foreach ( var notInB in valuesInA.Except(valuesInB))     Debug .WriteLine( string .Format( "Value not in TableB.BField: {0}" , notInB)); This is assuming that both AField and BField are the same type.