I have a linq query which fetches all records from the customer table to an observable collection as below:
customerList = new ObservableCollection<customer>(dbContext.customers);
dgRecords1.ItemsSource = customerList;
the list is bound to a datagrid.
The customer table contains many fields nearly hundred. But I display only a few fields on the datagrid. My question is
whether bringing of only selected fields from the database using linq query increase the speed the customer screen?
I need to filter and sometimes delete records from this list.
Which is the best way to select few fields into observable collection, Can someone give some sample linq queries?
Tips to optimize speed:
ObjectTrackingEnabledin LINQ-to-SQL) will reduce overheads post-processing the data… but frankly, when we had this problem, we solved it “once and for all” by writing “dapper”, and going old-school:
where
CustomerViewModelis a simple POCO type not related to LINQ etc that just has the required values, for example:This cuts out all unnecessary overheads, and is ideal when you just want to display data; additionally, the parameterization and materialization layers are very optimised (with strategy-caching, for optimum performance).