EntityFramework.DynamicFilters: v2.20 crashes loading child collection
Hi
After upgrading from 1.4.10.2 to v2.20
When running the following code;
MyData.Entry(entity).Collection(“ChildCmContacts”).Load();
where entity is a CmContact entity and ChildCmContacts is an ICollection<CmContact> I get a NullReferenceException
A global filter is declared in the OnModelCreating procedure of the DBContext modelBuilder.Filter(“DeletedFilter”, (IBaseObject d) =>d.Deleted, false);
This code works in 1.4.10.2
Listed Below ; Callstack, exception and entity model;
CallStack Attached
Exception
System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=EntityFramework.DynamicFilters
StackTrace:
at EntityFramework.DynamicFilters.DynamicFilterQueryVisitorCSpace.FindFiltersForEntitySet(ReadOnlyMetadataCollection1 metadataProperties, EntityContainer entityContainer) at EntityFramework.DynamicFilters.DynamicFilterQueryVisitorCSpace.Visit(DbScanExpression expression) at System.Data.Entity.Core.Common.CommandTrees.DbScanExpression.Accept[TResultType](DbExpressionVisitor
1 visitor)
at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.VisitExpression(DbExpression expression)
at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.VisitExpressionBinding(DbExpressionBinding binding)
at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.VisitExpressionBindingEnterScope(DbExpressionBinding binding)
at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.Visit(DbFilterExpression expression)
at System.Data.Entity.Core.Common.CommandTrees.DbFilterExpression.Accept[TResultType](DbExpressionVisitor1 visitor) at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.VisitExpression(DbExpression expression) at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.VisitExpressionBinding(DbExpressionBinding binding) at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.VisitExpressionBindingEnterScope(DbExpressionBinding binding) at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.Visit(DbProjectExpression expression) at System.Data.Entity.Core.Common.CommandTrees.DbProjectExpression.Accept[TResultType](DbExpressionVisitor
1 visitor)
at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.VisitExpression(DbExpression expression)
at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.VisitExpressionBinding(DbExpressionBinding binding)
at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.Visit(DbJoinExpression expression)
at System.Data.Entity.Core.Common.CommandTrees.DbJoinExpression.Accept[TResultType](DbExpressionVisitor1 visitor) at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.VisitExpression(DbExpression expression) at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.VisitExpressionBinding(DbExpressionBinding binding) at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.VisitExpressionBindingEnterScope(DbExpressionBinding binding) at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.Visit(DbProjectExpression expression) at System.Data.Entity.Core.Common.CommandTrees.DbProjectExpression.Accept[TResultType](DbExpressionVisitor
1 visitor)
at EntityFramework.DynamicFilters.DynamicFilterInterceptor.TreeCreated(DbCommandTreeInterceptionContext interceptionContext)
at System.Data.Entity.Infrastructure.Interception.DbCommandTreeDispatcher.<Created>b__0(IDbCommandTreeInterceptor i, DbCommandTreeInterceptionContext c)
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch[TInterceptionContext,TResult](TResult result, TInterceptionContext interceptionContext, Action
2 intercept)
at System.Data.Entity.Infrastructure.Interception.DbCommandTreeDispatcher.Created(DbCommandTree commandTree, DbInterceptionContext interceptionContext)
at System.Data.Entity.Core.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree, DbInterceptionContext interceptionContext)
at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlanFactory.CreateCommandDefinition(ObjectContext context, DbQueryCommandTree tree)
at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlanFactory.Prepare(ObjectContext context, DbQueryCommandTree tree, Type elementType, MergeOption mergeOption, Boolean streaming, Span span, IEnumerable1 compiledQueryParameters, AliasGenerator aliasGenerator) at System.Data.Entity.Core.Objects.EntitySqlQueryState.GetExecutionPlan(Nullable
1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery1.<>c__DisplayClass7.<GetResults>b__6() at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func
1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectQuery1.<>c__DisplayClass7.<GetResults>b__5() at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func
1 operation)
at System.Data.Entity.Core.Objects.ObjectQuery1.GetResults(Nullable
1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery1.Execute(MergeOption mergeOption) at System.Data.Entity.Core.Objects.DataClasses.EntityCollection
1.Load(List1 collection, MergeOption mergeOption) at System.Data.Entity.Core.Objects.DataClasses.EntityCollection
1.Load(MergeOption mergeOption)
at System.Data.Entity.Core.Objects.DataClasses.RelatedEnd.Load()
at System.Data.Entity.Internal.InternalNavigationEntry.Load()
at System.Data.Entity.Infrastructure.DbCollectionEntry.Load()
at FwBaseMVVM.BaseViewModels.DataContextAwareViewModelBase.OnLoadEntityChildren(Object entity) in C:\Projects\Source\CH.Framework.02\FwBaseMVVM\FwBaseMVVM\BaseViewModels\DataContextAwareViewModelBase.cs:line 55
at FmContactManager.ViewModels.VmContactManager.LoadContactGraph(CmContact contact) in C:\Projects\Source\CH.Framework.02\Modules\FmContactManager\ViewModels\VmContactManager.cs:line 1693
at FmContactManager.ViewModels.VmContactManager.set_MainContact(CmContact value) in C:\Projects\Source\CH.Framework.02\Modules\FmContactManager\ViewModels\VmContactManager.cs:line 145
at FmContactManager.ViewModels.VmContactManager…ctor(IUnityContainer container, IParentViewModelBase parentViewModel) in C:\Projects\Source\CH.Framework.02\Modules\FmContactManager\ViewModels\VmContactManager.cs:line 574
at FmContactManager.FmContactManagerService.ReturnVmContactManager(IParentViewModelBase registerViewModel) in C:\Projects\Source\CH.Framework.02\Modules\FmContactManager\FmContactManagerService.cs:line 18
at SBPFClientRegister.ViewModels.VmClientEdit.PostConstruction() in C:\Projects\Source\iProg.SimonBeaujiePictureFrames\SBPFClientRegister\ViewModels\VmClientEdit.cs:line 91
at SBPFClientRegister.ViewModels.VmClientEdit…ctor(IUnityContainer container, Int32 id) in C:\Projects\Source\iProg.SimonBeaujiePictureFrames\SBPFClientRegister\ViewModels\VmClientEdit.cs:line 72
at SBPFClientRegister.Decorations.ClientOrderProcessingHeaderDecoratorService.GetViewModel(Int32 id) in C:\Projects\Source\iProg.SimonBeaujiePictureFrames\SBPFClientRegister\Decorations\ClientOrderProcessingHeaderDecoratorService.cs:line 25
at FmOrderProcessing.ViewModels.VmOpDocumentManager.ManualAddDecorators() in C:\Projects\Source\CH.Framework.02\Modules\FmOrderProcessing\ViewModels\VmOpDocumentManager.cs:line 227
at FwBaseMVVM.ViewModelBase.ProcessDecorators() in C:\Projects\Source\CH.Framework.02\FwBaseMVVM\FwBaseMVVM\BaseClasses\ViewModelBase.cs:line 216
at FwBaseMVVM.ViewModelBase.PostConstruction() in C:\Projects\Source\CH.Framework.02\FwBaseMVVM\FwBaseMVVM\BaseClasses\ViewModelBase.cs:line 193
at FwBaseMVVM.BaseViewModels.ProcessingViewModelBase`1.PostConstruction() in C:\Projects\Source\CH.Framework.02\FwBaseMVVM\FwBaseMVVM\BaseViewModels\ProcessingViewModelBase.cs:line 73
at FmOrderProcessing.ViewModels.VmOpDocumentManager.PostConstruction() in C:\Projects\Source\CH.Framework.02\Modules\FmOrderProcessing\ViewModels\VmOpDocumentManager.cs:line 172
at FmOrderProcessing.ViewModels.VmOpDocumentManager…ctor(IUnityContainer container, Int32 id) in C:\Projects\Source\CH.Framework.02\Modules\FmOrderProcessing\ViewModels\VmOpDocumentManager.cs:line 167
InnerException:
The Entity using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations.Schema; using FwBase.Attributes; using FwBaseEntityFramework; using FwInterfaces.ContactManager;
namespace FmContactManager { public class CmContact : BusinessObject, ICmContact {
region ReadOnly Properties
[NotMapped]
[Browsable(false)]
public string Name
{
get
{
if (CmContactType == null)
return "New Record";
switch (CmContactType.ContactTypeEnum)
{
case ContactType.Person:
if (CmContactPersonDetail != null)
return CmContactPersonDetail.FullName;
return "Null Person Detail!";
case ContactType.Organisation:
if (CmContactOrganisationDetail != null)
return CmContactOrganisationDetail.Name;
return "Null Organisation Detail";
default:
return "Undefined Type";
}
}
}
[DisplayName("Type And Name")]
[NotMapped]
public string TypeAndName
{
get
{
if (CmContactType != null)
return CmContactType.Description + " : " + Name;
return "NULL Contact Type";
}
}
[DisplayName("Contact Type")]
[NotMapped]
[Browsable(false)]
public string ContactTypeDescription
{
get
{
if (CmContactType != null)
return CmContactType.Description;
return "NULL Contact Type";
}
}
private System.Guid _tempLookup = System.Guid.NewGuid();
[Browsable(false)]
[NotMapped]
public System.Guid TempLookup
{
get { return _tempLookup; }
set { _tempLookup = value; }
}
endregion \ReadOnly Properties
public CmContact()
{
ChildCmContacts = new HashSet<CmContact>();
CmCommunicationMethods = new HashSet<CmCommunicationMethod>();
CmAddresses = new HashSet<CmAddress>();
}
#region Database Fields
#endregion Database Fields
#region Associations
[Browsable(false)]
public int? CmContactTypeID { get; set; }
private CmContactType cmContactType;
//[Required]
[Browsable(false)]
public virtual CmContactType CmContactType
{
get { return cmContactType; }
set { CheckPropertyChanged(ref cmContactType, value); }
}
[Browsable(false)]
public virtual int? CmContactOrganisationDetailID { get; set; }
private CmContactOrganisationDetail _cmContactOrganisationDetail;
[Browsable(false)]
public virtual CmContactOrganisationDetail CmContactOrganisationDetail
{
get { return _cmContactOrganisationDetail; }
set { CheckPropertyChanged(ref _cmContactOrganisationDetail, value); }
}
[Browsable(false)]
public virtual int? CmContactPersonDetailID { get; set; }
private CmContactPersonDetail _cmContactPersonDetail;
[Browsable(false)]
public virtual CmContactPersonDetail CmContactPersonDetail
{
get { return _cmContactPersonDetail; }
set { CheckPropertyChanged(ref _cmContactPersonDetail, value); }
}
[Browsable(false)]
[EntityChildCollection]
public virtual ICollection<CmContact> ChildCmContacts { get; set; }
[Browsable(false)]
[EntityChildCollection]
public virtual ICollection<CmCommunicationMethod> CmCommunicationMethods { get; set; }
[Browsable(false)]
[EntityChildCollection]
public virtual ICollection<CmAddress> CmAddresses { get; set; }
#endregion //Associations
#region Custom Error Checking
public override void RunCustomErrorDetection()
{
if (CmContactType == null)
AddError("CmContactType", "Please select a contact type");
if (CmContactOrganisationDetail != null)
if (!CmContactOrganisationDetail.Deleted)
CmContactOrganisationDetail.ValidateNow();
if (CmContactPersonDetail != null)
if (!CmContactPersonDetail.Deleted)
CmContactPersonDetail.ValidateNow();
foreach (var cmCommunicationMethod in CmCommunicationMethods)
{
cmCommunicationMethod.ValidateNow();
}
foreach (var cmAddress in CmAddresses)
{
cmAddress.ValidateNow();
}
foreach (var childCmContact in ChildCmContacts)
{
childCmContact.ValidateNow();
}
base.RunCustomErrorDetection();
}
public override string GetChildErrors()
{
string error = "";
if (CmContactOrganisationDetail != null)
if (CmContactOrganisationDetail.HasErrors)
error = error + CmContactOrganisationDetail.Error;
if (CmContactPersonDetail != null)
if (CmContactPersonDetail.HasErrors)
error = error + CmContactPersonDetail.Error;
foreach (var cmCommunicationMethod in CmCommunicationMethods)
{
if (cmCommunicationMethod.HasErrors)
error = error + cmCommunicationMethod.Error;
}
foreach (var cmAddress in CmAddresses)
{
if (cmAddress.HasErrors)
error = error + cmAddress.Error;
}
foreach (var childCmContact in ChildCmContacts)
{
error = error + childCmContact.Error;
}
return error;
}
#endregion //Custom Error Checking
}
}
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 1
- Comments: 17
Commits related to this issue
- #71: Fixed issue with entry.Load() on child collections — committed to zzzprojects/EntityFramework.DynamicFilters by jcachat 8 years ago
Thanks - that helps a lot. I thought about making that same type of change to avoid the exception but I’m worried that may just silently skip a filter. I will look into it over the weekend and let you know what I find.