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

Report with ObjectDataSource on EF/POCO Objects. Preview Error

2 Answers 84 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Simon Christ
Top achievements
Rank 1
Simon Christ asked on 15 Dec 2012, 04:10 PM

Hello 

I want to build reports based on ObjectDataSource. As an easy sample, I tried to start with an sample report, based on your video.

In my project, there is a BI-Layer based on EF4/POCO. But when I try to add a Entity Context Object (to populate the List in GetAllProducts()), I get an Error on Report Preview (see Attachment).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using IW_CCFA_GEKO.Model;
 
namespace IW_CCFA_GEKO.Report.ReportModels
{
    [DataObject]
    public class Products
    {
        protected CCFAGEKOEntities db = new CCFAGEKOEntities();
 
        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<Product> GetAllProducts()
        {
            var products = new List<Product>();
 
            products.Add(new Product() {Name = "Produkt 1", Color = "blau", ListPrice = 2.55, ProductNumber = "654-789"});
            products.Add(new Product() {Name = "Produkt 2", Color = "gelb", ListPrice = 1.20, ProductNumber = "345-768"});
            products.Add(new Product() {Name = "Produkt 3", Color = "rot", ListPrice = 5.0, ProductNumber = "56-334"});
            products.Add(new Product() {Name = "Produkt 4", Color = "grĂ¼n", ListPrice = 3.9, ProductNumber = "234-159"});
 
            return products;
        }
    }
}

In the same Project, I made a report, directly based on an EntityDataSource, which works, even in Preview. But I need to do some processing in my own Classes before.
What's wrong and how to resolve it?

Thanks, Simon

2 Answers, 1 is accepted

Sort by
0
Squall
Top achievements
Rank 1
answered on 18 Dec 2012, 02:34 PM
Hi,
You can try to extend the model: http://www.telerik.com/help/reporting/entitydatasource-connecting-to-entity-data-model.html
SN
0
Mars
Top achievements
Rank 1
answered on 20 Dec 2012, 06:36 AM
I've solved this issue in this way:
public sealed class DataSourceManager
   {
       #if DEBUG
       TagDbContext context = new TagDbContext(@"Server=.\SQLEXPRESS;Database=testbase;Integrated Security=True;");
       #else
       TagDbContext context = new TagDbContext();
       #endif
       public IList<TagValue> GetPrintTenderData()
       {
           return context.TagValues
               .Where(t => t.TagID == 1 && t.DateTime > new DateTime(2012, 10, 1))
               .Take(10)
               .ToList();
       }
    }
Tags
General Discussions
Asked by
Simon Christ
Top achievements
Rank 1
Answers by
Squall
Top achievements
Rank 1
Mars
Top achievements
Rank 1
Share this question
or