Hello,
I am attempting to execute a stored procedure that returns data with exactly the same columns as that of a table Entity I have in my project. I set the 'Returns a Collection Of' property in the 'Add Function Import' dialog to my entity type.
I get a NullReferenceException error when executing the stored procedure and on further digging it seems that it is because the 'EntityKey' property is missing. Is there anything I can do to tell it to ignore those special properties of the Entity?
I already have a partial class for that entity with '[ScaffoldColumn(false)]' but that doesn't seem to matter.
Cheers, Nick
EDIT:
Here is the stack trace:
[NullReferenceException: Object reference not set to an instance of an object.] System.Data.EntityKey.AddHashValue(Int32 hashCode, Object keyValue) +36 System.Data.EntityKey.GetHashCode() +7696654 System.Collections.Generic.GenericEqualityComparer
1.GetHashCode(T obj) +23 System.Collections.Generic.Dictionary
2.FindEntry(TKey key) +70 System.Collections.Generic.Dictionary2.TryGetValue(TKey key, TValue& value) +17 System.Data.Objects.ObjectStateManager.TryGetEntityEntry(EntityKey key, EntityEntry& entry) +111 System.Data.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly(Func
2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet) +102 lambda_method(Closure , Shaper ) +460 System.Data.Common.Internal.Materialization.Coordinator1.ReadNextElement(Shaper shaper) +170 System.Data.Common.Internal.Materialization.SimpleEnumerator.MoveNext() +84 System.Collections.Generic.List
1..ctor(IEnumerable1 collection) +406 System.Linq.Enumerable.ToList(IEnumerable
1 source) +58 TWAgencySpend.Controllers.ReportsController.Advertising(Nullable1 agencyId, Nullable
1 businessUnitId) in C:\dasdsd\Controllers\ReportsController.cs:72 lambda_method(Closure , ControllerBase , Object[] ) +190 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +51 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +409 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
2 parameters) +52 System.Web.Mvc.<>c_DisplayClassd.b_a() +127 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) +436 System.Web.Mvc.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c() +61 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList
1 filters, ActionDescriptor actionDescriptor, IDictionary2 parameters) +305 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +830 System.Web.Mvc.Controller.ExecuteCore() +136 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +111 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +39 System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +65 System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +44 System.Web.Mvc.Async.<>c__DisplayClass8
1.b__7(IAsyncResult _) +42 System.Web.Mvc.Async.WrappedAsyncResult`1.End() +141 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +54 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +52 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8836913 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
Updated: Here is the item in the SSDL for the function:
<Function Name="GetAgencyReport" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo">
<Parameter Name="AgencyId" Type="int" Mode="In" />
<Parameter Name="Year" Type="int" Mode="In" />
</Function>
and here is the call:
reportsViewModel.AgencyReportData = twAgencySpendEntities.GetAgencyReport(agencyId.Value, 2010).ToList();
and here is the key for my Entity:
<EntityType Name="AdvertisingData">
<Key>
<PropertyRef Name="AgencyId" />
<PropertyRef Name="BusinessUnitId" />
<PropertyRef Name="Month" />
<PropertyRef Name="Year" />
</Key>
<Property Name="AgencyId" Type="int" Nullable="false" />
<Property Name="BusinessUnitId" Type="int" Nullable="false" />
<Property Name="Month" Type="int" Nullable="false" />
<Property Name="Year" Type="int" Nullable="false" />
...