NopCommerce4.2 common error and exception handling - Lazy-loaded navigation properties must have backing fields

An error occurred while starting the application.

InvalidOperationException: No field was found backing property 'WeiActivityWinInfos' of entity type 'WeiActivityInfo'. Lazy-loaded navigation properties must have backing fields. Either name the backing field so that it is picked up by convention or configure the backing field to use.

Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.ValidateFieldMapping(IModel model)

InvalidOperationException: No field was found backing property 'WeiActivityWinInfos' of entity type 'WeiActivityInfo'. Lazy-loaded navigation properties must have backing fields. Either name the backing field so that it is picked up by convention or configure the backing field to use.

The above problems, mainly non-standard navigation property named due

error code

  public partial class WeiActivityInfo : BaseEntity
    {

        private ICollection<WeiActivityWinInfo> _weiActivityWinInfo;
   
        public virtual ICollection<WeiActivityWinInfo> WeiActivityWinInfos
        {
            get { return _weiActivityWinInfo?? (_weiActivityWinInfo= new List<WeiActivityWinInfo>()); }
            protected set { _weiActivityWinInfo= value; }
        }
    }

 

 EF navigation configuration name to be consistent, otherwise this error, the correct configuration to ensure

private and public set of attributes match the name!

 

public partial class WeiActivityInfo : BaseEntity
    {

        private ICollection<WeiActivityWinInfo> _weiActivityWinInfos;
   
        public virtual ICollection<WeiActivityWinInfo> WeiActivityWinInfos
        {
            get { return _weiActivityWinInfos?? (_weiActivityWinInfos= new List<WeiActivityWinInfo>()); }
            protected set { _weiActivityWinInfos= value; }
        }
    }

 

Guess you like

Origin www.cnblogs.com/chenyuxi/p/11924760.html