This is a migrated thread and some comments may be shown as answers.

Understanding Binding to IEnumerable<T>

3 Answers 237 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Graeme
Top achievements
Rank 1
Graeme asked on 16 Sep 2013, 11:28 PM
We are looking for a reporting solution that will easily work with our existing read architecture. All of our read queries are returned from Query handler with an interface 
IQueryHandler<TQuery, TResult>

TQuery is a query with various parameters e.g. Employee Type etc
TResult is in most cases IEnumerable<T> E.g. we could have a person query whose return type is IEnumerable<Person>.

These queries are custom projections with various business logic in them so we can't go direct to the database.  

Can Telerik reporting easily be used to create reports and bind to a result type of IEnumerable<T>? We don't want to bind to something which implements IEnumerable<T> we want to bind something which is a IEnumerable<T>. We would like the report to be able to pass parameters which we could use to populate our Query object.

Also when is Telerik Reporting Q3 release estimated to be out? We want to use it in an MVC app (which I appreciate older versions can be) but it sounds a better experience in the next release

Any advice would be appreciated

3 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 19 Sep 2013, 09:24 AM
Hello Graeme,

For your scenario you can use the ObjectDataSource Component. In your case the DataSource is a business object and the DataMember property specifies the name of the method which should be invoked to retrieve the data. To populate your query object use the arguments of this method which can be specified through the Parameters collection of the ObjectDataSource component.

For more information on the topic, please follow the How to: Bind to a BusinessObject and Using Parameters with the ObjectDataSource Component help articles.

You can expect the Telerik Reporting Q3 2013 to be released in mid-October. Still we are currently preparing the first beta with the MVC viewer and we will release it in a few days. We will announce the beta with a blog.

Regards,
Nasko
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

0
Graeme
Top achievements
Rank 1
answered on 19 Sep 2013, 10:03 AM
Are there any available samples that demonstrate this functionality?

Also are the attributes all required? Is there a non attribute based way?

Or general structure is:

    public interface IQueryHandler<in TQuery, out TResult>
        where TQuery : IQuery<TResult>
    {
        TResult Handle(TQuery query);
    }


public class CompanyQueryHandlers : IQueryHandler<AllCompaniesQueryIEnumerable<Company>>  {
        private readonly DomainContext context;

        public CompanyQueryHandlers(DomainContext context)
        {
            this.context = context;
        }
 
        public IEnumerable<Company> Handle(AllCompaniesQuery query)
        {
            var companies = 
                context.Companies.Where(company=>company.Type==query.CompanyType)
                    .Include(company => company.Locations)
                    .Include(c => c.CompanyAccountingCodeNumbers)
                    .Include(c => c.CompanyAccountingCodeNumbers.Select(a => a.AccountingCode))	
                    .OrderBy(company => company.Name)
            return companies;
        }
}

Where would we need to put the Attributes in this case? This is pulled together via DI so we are only passing in the interface to the controller etc. 

Thanks
0
Nasko
Telerik team
answered on 23 Sep 2013, 03:41 PM
Hi Graeme,

You can omit the attributes, as they are not mandatory. However, Telerik Reporting is not aware of your DomainContext and AllCompaniesQuery classes and will not instantiate the CompanyQueryHandlers.
The best approach is to create another data-access layer on top of your current one, where you will handle the creation of the CompanyQueryHandlers and will translate simple parameters (for e.g. int, string, etc..) to the required AllCompaniesQuery. 

As for the examples, aside from the help articles, there are sample reports which come with the installation of Telerik Reporting and one of the reports is using the ObjectDataSource component.

If you can create a simple runnable scenario that you can send us, we will look into it locally and show you how to use it with Telerik Reporting. 

Regards,
Nasko
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

Tags
General Discussions
Asked by
Graeme
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Graeme
Top achievements
Rank 1
Share this question
or