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:
Here's the code for one of the entity objects that I'm using:
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.
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.