Ian Blackburn

Linq

Linq Performance with Generic Lists

** UPDATE * - this is messed up!  read the comments for more details... A question came up today on MsWebDev as follows: I have two lists of integers, each with approximately 300,000 integers in them. I need to work out which integers are in List A but not in List B. Their first thought was to "literate through List A and ask if List B contains the current integer. If it doesn’t then I add it to a third list and return that at the end", but this was giving poor performance (10 minutes!) The use of a Hashtable was suggested, and...

Silverlight ObservableCollections from WCF and Linq to Sql

I have a ListBox in a Silverlight 2.0 app that is bound to some data coming from a WCF service that is returned from Linq to Sql.  The service is simplicity itself:   public List<CourseSection> GetCourseSections() { CoursesDataContext db = new CoursesDataContext(); return db.CourseSections.ToList(); }   Note: you have to mark your DataContext Serialization Mode as Unidirectional for the above to work (as shown)   I added a Service Reference to this from Silverlight and bound the data to a ListBox: private void Button_Click(object sender, RoutedEventArgs e) { CoursesService.CourseServiceClient client = new CourseBuilder.CoursesService.CourseServiceClient(); client.GetCourseSectionsCompleted +=          ...

Linq to SQL Nulls

The way Linq to Sql deals with nulls had me scratching my head initially.  At first things seemed simple - for example the following does exactly what you would expect (Mike Taulty goes into more details on why here): Customers.Where(c => c.Region==null) This resolves to the following SQL: SELECT [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Address],        [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Country], [t0].[Phone], [t0].[Fax] FROM [Customers] AS [t0] WHERE [t0].[Region] IS NULL Notice that the Where clause uses IS NULL rather than = null which is correct.  However if I pass a null parameter to the query then the SQL is resolved incorrectly.  For example: string region=null; Customers.Where (c => c.Region==region); This...