I have a stored procedure GetMyTime. It has one parameter int PersonID, and return a datatime. After add it to EDMX and import it as a function. Then I try to mock up 4.0 to write a code as below:
public ObjectResult<Nullable<global::System.DateTime>> GetMyTime(Nullable<global::System.Int32> PersonID)
{
ObjectParameter[] PersonIDParameters;
if (PersonID.HasValue)
{
PersonIDParameters = new ObjectParameter[]{new ObjectParameter("PersonID", PersonID)};
}
else
{
PersonIDParameters = new ObjectParameter[]{new ObjectParameter("PersonID",typeof(global::System.Int32))};
}
return base.ExecuteFunction<Nullable<global::System.DateTime>>("GetMyTime", PersonIDParameters); //this line cause error
}
But I get a error at the last line: Error 2 The type 'System.DateTime?' cannot be used as type parameter 'TElement' in the generic type or method 'System.Data.Objects.ObjectContext.ExecuteFunction(string, params System.Data.Objects.ObjectParameter[])'. There is no boxing conversion from 'System.DateTime?' to 'System.Data.Objects.DataClasses.IEntityWithChangeTracker'.
How to fix it?