I am very new to Linq.
Today, I was trying to use Linq in silverlight code behind together with ListBase object
For example, my dataportal will get all customers from database, then in the silverlight UI
I would like to do some filtering work such as only show customers who had first name starts with letter "A" and then bind the filtered data to a datagrid.
public void BindDataGrid()
{
CslaDataProvider provider = this.DataContext as CslaDataProvider;
ROCustomers customers = provider.Data as ROCustomers;
var customers= from customer in customers where customer.FirstName.StartsWith("A")
select customer;
CustomerDG.ItemsSource = customers.ToArray();
}
This code seems work, but I am not very confident at this point. I would like to seek your input on this manner
On Silverlight CSLA does nothing special with LINQ. So you will get standard LINQ to Objects behaviors - which means the result of a query is an IEnumerable<T>.
This means that if you add or remove items from the query result they will NOT be added or removed from the real list, and so the add/remove operation won't be persisted when you save the real collection.
Also, IEnumerable<T> doesn't raise any changed events unless you use it to create a new ObservableCollection<T>.
Otherwise you can bind the IEnumerable<T> result to the UI and it should work pretty well.
Thank you for the answer.
Copyright (c) Marimer LLC