I have a table with several columns (clm1-clm10). The datagrid is populated with all columns as follows:
MyTableDomainContext context = new MyTableDomainContext();
dataGrid1.ItemsSource = context.DBTables;
context.Load(context.GetDBTablesQuery());
GetDBTablesQuery()
is defined in domainservices.cs
as follows:
public IQueryable<DBTable> GetDBTables()
{
return this.ObjectContext.DBTables;
}
How can I displayed only two columns (e.g. clm1 and clm5) using the select lambda expression?
Is this what you are looking for?
GetDBTables().Select(o => new { o.clm1, o.clm5 });
It will result in an anonymous type. If you want it to result in some type you have defined it could something like this:
GetDBTables().Select(o => new MyViewModel { clm1 = o.clm1, clm5 = o.clm5 });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With