I know there has been many questions on this topic. However, I am really confused why I get this exception in this case.
The exception
ObjectDataSource 'investmentDataSource' could not find a non-generic method 'GetAll' that has no parameters
The case The environment - .net 3.5, asp, SharePoint 2010 (this does not matter)
The repository object inherits from a generic repository object and it looks like this:
public class InvestmentRepository : Repository<Investment, EntityContext>, IInvestmentRepository
{
// ...
}
The generic repository looks like this:
public abstract class Repository<TEntity, TContext> : IRepository<TEntity>
where TEntity : EntityObject, new()
where TContext : ObjectContext, new()
{
public IQueryable<TEntity> GetAll()
{
// returns all entities from context
}
}
I suppose that during the compilation a method on the InvestmentRepository is created which looks like this:
public IQueryable<Investment> GetAll()
So I suppose that when I create an ObjectDataSource like this:
<asp:ObjectDataSource
ID="investmentDataSource"
runat="server"
OnObjectCreating="DataSourceObjectCreating"
TypeName="Model.InvestmentRepository"
SelectMethod="GetAll">
</asp:ObjectDataSource>
... it should work. However, it does not work. I am looking for any suggestions. Thanks
The suggestion would be to put another auxiliary adapter class between your repository and your ObjectDataSource.
It will be much easier to controll all possible parameter combinations with such adapter than trying to make a circle from a square (read: making your generic repository working directly as the object data source's data provider).