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

Entity Data Source error while processing report.

1 Answer 69 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 22 Feb 2012, 05:33 PM
I get an error(in the designer preview) that reads "An error has occured while processing Report 'MyReport': Unable to cast the type 'System.Nullable '1' to type 'System.Object'. LINQ to Entities only supports casting Entity Data Model primitive types."

I know that this has to do with the datasource I'm choosing to use. I'm 'extending' the model's Entity partial class with a method that should return an enumerable collection of classes that contain my data that I pulled from the model with LINQ. Sort of like the code that is given here: http://www.telerik.com/ClientsFiles/311739_EntityFrameworkDemo.zip

Here's the method I'm using to get data:
public partial class MyDataModelEntities
    {
        public IEnumerable<SessioinReportData> QuerySessionReport()
        {
            var query = from user in this.users
                        from session in this.sessions
                        where user.id.Equals(session.assigned_user_id)
                        select new SessioinReportData
                        {
                            CreatedBy = user.user_name ?? "",
                            SessionType = session.session_type ?? "Unknown",
                            DateEntered = (session.date_entered != null ? session.date_entered.Value.ToString("MM/dd/yyyy") : "n/a"),
                            NumericID = session.numeric_id,
                            Status = session.status
                        };
            return query;
        }
         
    }
 
    /// <summary>
    /// This contains data needed for the report
    /// </summary>
    public class SessioinReportData
    {
        public string CreatedBy { get; set; }
        public string SessionType { get; set; }
        public string DateEntered { get; set; }
        public int NumericID { get; set; }
        public string Status { get; set; }
         
    }

Here's the code for one of the entity objects that I'm using:
namespace MyProject.Web.Model
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;
 
    // The MetadataTypeAttribute identifies sessionMetadata as the class
    // that carries additional metadata for the session class.
    [MetadataTypeAttribute(typeof(session.sessionMetadata))]
    public partial class session
    {
        internal sealed class sessionMetadata
        {
 
            // Metadata classes are not meant to be instantiated.
            private sessionMetadata()
            {
            }
 
            public Nullable<Guid> assigned_user_id { get; set; }
 
            public Nullable<bool> confirm_flag { get; set; }
 
            public Nullable<Guid> created_by { get; set; }
 
            public Nullable<DateTime> date_end { get; set; }
 
            public Nullable<DateTime> date_entered { get; set; }
 
            public Nullable<DateTime> date_modified { get; set; }
 
            public Nullable<DateTime> date_start { get; set; }
 
            public Guid id { get; set; }
 
            public Nullable<Guid> modified_user_id { get; set; }
 
            public string notes { get; set; }
 
            public Nullable<Guid> parent_id { get; set; }
 
            public string session_type { get; set; }
 
            public string status { get; set; }
        }
    }
}

I've tried adjusting for the Nullable types in a dew different ways. Nothing seems to work. If you don't know of any suggestions on how to fix this, at least tell me what you think the problem lies with.

1 Answer, 1 is accepted

Sort by
0
Hrisi
Telerik team
answered on 27 Feb 2012, 02:27 PM
Hello Mike,

One way to discover what is going wrong is to use QuerySessionReport method in the test. I guess you have not tested this method with your actual data. Because we do not know your data we cannot guess/test your methods, there is a possibility the problem is hidden in your LINQ query.

A similar problem is described here, where you can find a possible solution.

All the best,
Hrisi
the Telerik team
NEW in Q1'12: Telerik Report Designer (Beta) for ad-hoc report creation. Download as part of Telerik Reporting Q1 2012. For questions and feedback, use the new Telerik Report Designer Forum.
Tags
General Discussions
Asked by
Mike
Top achievements
Rank 1
Answers by
Hrisi
Telerik team
Share this question
or