我正在嘗試執行一個存儲過程,該實體返回的數據與我在項目中使用的表實體的列完全相同。我在'添加功能導入'對話框中將'收集'屬性設置爲我的實體類型。實體框架與返回實體的'獲取'存儲過程
當執行存儲過程和進一步挖掘時,我得到一個NullReferenceException錯誤,似乎是因爲'EntityKey'屬性丟失。我能做些什麼來告訴它忽略實體的特殊屬性?
我已經有了'[ScaffoldColumn(false)]'的實體的部分類,但這似乎並不重要。
乾杯, 尼克
編輯:
這裏是堆棧跟蹤:
[NullReferenceException異常:未設置爲一個對象的實例對象引用] 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的鍵)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(封閉,牛頭刨牀)460 System.Data.Common.Internal.Materialization.Coordinator1.ReadNextElement(Shaper shaper) +170 System.Data.Common.Internal.Materialization.SimpleEnumerator.MoveNext() +84 System.Collections.Generic.List
1 ..(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參數)+52 System.Web.Mvc。 <> c__DisplayClassd.b__a()127 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter濾波器,ActionExecutingContext preContext,函數功能1 continuation) +436 System.Web.Mvc.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c() +61 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList
1個濾波器,ActionDescriptor actionDescriptor,IDictionary的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.<>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,對象標記)+ 40 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult的asyncResult)+52 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult的結果)+38 System.Web.CallHandlerExecutionStep。的System.Web .HttpApplication.IExecutionStep.Execute()+8836913 System.Web.HttpApplication。ExecuteStep(IExecutionStep一步,布爾& completedSynchronously)184
更新:這裏是該函數在SSDL項目:
<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>
,這裏是電話:
reportsViewModel.AgencyReportData = twAgencySpendEntities.GetAgencyReport(agencyId.Value, 2010).ToList();
這裏是我的實體的關鍵:
<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" />
...
您可以顯示堆棧嗎? – 2010-05-04 13:48:58
你有一段代碼嗎?因爲大部分時間這會導致一個沒有實例化的對象。 – pipelinecache 2010-05-04 16:20:25
如何在EDMX中映射密鑰?即,對於這個過程,SSDL中的''值是什麼? –
2010-05-04 21:04:38