Reputation: 189
This is a SL/WPF application, trying to display two columns. The following code:
MyDomainContext context = new MyDomainContext();
dataGrid1.ItemsSource = context.DBTables;
context.Load(context.GetTwoDataBasesQuery())
;
The domainservice.cs contains the method definition as follows:
public IQueryable<DBTable>GetTwoDataBases()
{
return this.ObjectContext.DBTables;
}
This code works fine but returns all columns in the context I need to return only two columns so changed is as follows
public IQueryable<DBTable>GetTwoDataBases()
{
//trying to return columns
return GetDBTables().Select(m => new { m.col1, m.col2 });
}
But compiler generates errors, does not accept the “return”.
following error Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Linq.IQueryable'. An explicit conversion exists.
How to return two columns only? many thanX
Upvotes: 3
Views: 66
Reputation: 148110
You are returning the anonymous type but the return type of collection you have is DBTable
. You can make the return type object
or define a new class
and create object of that class.
Making object as return type
public object GetTwoDataBases()
{
//trying to retrun columns
return GetDBTables().Select(m => new { m.col1, m.col2 });
}
OR, returning IQueryable instead of anonymous type
public IQueryable<YourCustomType>GetTwoDataBases()
{
//trying to retrun columns
return GetDBTables()
.Select(m => new YourCustomType { YourCustomTypeProperty1 = m.col1, YourCustomTypeProperty2 = m.col2 });
}
Upvotes: 1