Note that there are some explanatory texts on larger screens.

plurals
  1. POEntity Framework with 'Get' Stored Procedure that returns Entities
    primarykey
    data
    text
    <p>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.</p> <p>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?</p> <p>I already have a partial class for that entity with '[ScaffoldColumn(false)]' but that doesn't seem to matter.</p> <p>Cheers, Nick</p> <p>EDIT:</p> <p>Here is the stack trace:</p> <blockquote> <p>[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<code>1.GetHashCode(T obj) +23 System.Collections.Generic.Dictionary</code>2.FindEntry(TKey key) +70 System.Collections.Generic.Dictionary<code>2.TryGetValue(TKey key, TValue&amp; value) +17 System.Data.Objects.ObjectStateManager.TryGetEntityEntry(EntityKey key, EntityEntry&amp; entry) +111 System.Data.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly(Func</code>2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet) +102 lambda_method(Closure , Shaper ) +460 System.Data.Common.Internal.Materialization.Coordinator<code>1.ReadNextElement(Shaper shaper) +170 System.Data.Common.Internal.Materialization.SimpleEnumerator.MoveNext() +84 System.Collections.Generic.List</code>1..ctor(IEnumerable<code>1 collection) +406 System.Linq.Enumerable.ToList(IEnumerable</code>1 source) +58 TWAgencySpend.Controllers.ReportsController.Advertising(Nullable<code>1 agencyId, Nullable</code>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, IDictionary<code>2 parameters) +409 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary</code>2 parameters) +52 System.Web.Mvc.&lt;>c__DisplayClassd.b__a() +127 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func<code>1 continuation) +436 System.Web.Mvc.&lt;&gt;c__DisplayClassf.&lt;InvokeActionMethodWithFilters&gt;b__c() +61 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList</code>1 filters, ActionDescriptor actionDescriptor, IDictionary<code>2 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.&lt;&gt;c__DisplayClass8.&lt;BeginProcessRequest&gt;b__4() +65 System.Web.Mvc.Async.&lt;&gt;c__DisplayClass1.&lt;MakeVoidDelegate&gt;b__0() +44 System.Web.Mvc.Async.&lt;&gt;c__DisplayClass8</code>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&amp; completedSynchronously) +184</p> </blockquote> <p>Updated: Here is the item in the SSDL for the function:</p> <pre><code> &lt;Function Name="GetAgencyReport" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo"&gt; &lt;Parameter Name="AgencyId" Type="int" Mode="In" /&gt; &lt;Parameter Name="Year" Type="int" Mode="In" /&gt; &lt;/Function&gt; </code></pre> <p>and here is the call:</p> <pre><code>reportsViewModel.AgencyReportData = twAgencySpendEntities.GetAgencyReport(agencyId.Value, 2010).ToList(); </code></pre> <p>and here is the key for my Entity:</p> <pre><code>&lt;EntityType Name="AdvertisingData"&gt; &lt;Key&gt; &lt;PropertyRef Name="AgencyId" /&gt; &lt;PropertyRef Name="BusinessUnitId" /&gt; &lt;PropertyRef Name="Month" /&gt; &lt;PropertyRef Name="Year" /&gt; &lt;/Key&gt; &lt;Property Name="AgencyId" Type="int" Nullable="false" /&gt; &lt;Property Name="BusinessUnitId" Type="int" Nullable="false" /&gt; &lt;Property Name="Month" Type="int" Nullable="false" /&gt; &lt;Property Name="Year" Type="int" Nullable="false" /&gt; ... </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload