我为自己的表创建了自己的PXGraph类,当我创建实例()时会抛出错误。错误是“ System.NullReferenceException:对象引用未设置为对象的实例”。同样由于某种原因,它不会在我的开发环境中发生-仅在部署后的生产环境中发生。
调用堆栈:
at PX.Data.PXSelectorAttribute.populateFields(PXCache sender, Boolean bypassInit)
at PX.Data.PXSelectorAttribute.CacheAttached(PXCache sender)
at PX.Data.PXEventSubscriberAttribute.InvokeCacheAttached(PXCache cache)
at PX.Data.PXCache`1..ctor(PXGraph graph)
at PX.Data.PXCacheCollection.get_Item(Type key)
at PX.Data.PXView.get_Cache()
at PX.Data.PXRestrictorAttribute.AlterCommand(PXCache sender)
at PX.Data.PXRestrictorAttribute.CacheAttached(PXCache sender)
at PX.Data.PXAggregateAttribute.CacheAttached(PXCache sender)
at PX.TM.PXOwnerSelectorAttribute.CacheAttached(PXCache sender)
at PX.Data.PXEventSubscriberAttribute.InvokeCacheAttached(PXCache cache)
at PX.Data.PXCache`1..ctor(PXGraph graph)
at PX.Data.PXCacheCollection.get_Item(Type key)
at PX.Data.PXView..ctor(PXGraph graph, Boolean isReadOnly, BqlCommand select)
at PX.Data.PXSelect`2..ctor(PXGraph graph)
at _Initialize(PXGraph )
at PX.Data.PXGraph._InitializeDelegate.Invoke(PXGraph graph)
at PX.Data.PXGraph..ctor()
at PX.Data.PXGraph`1..ctor()
at Aktion.Acumatica.RoyalBay.Customizations.SubscribeTRGData.Graphs.AKTRGItemClassMapMaint..ctor()
at PX.Data.PXGraph.CreateInstance(Type graphType, String prefix)
at PX.Data.PXGraph.CreateInstance(Type graphType)
at PX.Data.PXGraph.CreateInstance[Graph]()
图类:
public class AKTRGItemClassMapMaint : PXGraph<AKTRGItemClassMapMaint>
{
public PXSelect<AKTRGItemClassMap,
Where<AKTRGItemClassMap.trgItemClassCD, Equal<Required<AKTRGItemClassMap.trgItemClassCD>>>> TRGItemClassMaps;
public PXSelect<INSetup> Settings;
public PXSelect<INItemClass,
Where<INItemClass.itemClassID, Equal<Required<INItemClass.itemClassID>>>> ClassItems;
}
CreateInstance调用:
var classMapGraph = PXGraph.CreateInstance<AKTRGItemClassMapMaint>();
表结构:
CREATE TABLE [dbo].[AKTRGItemClassMap](
[CompanyID] [int] NOT NULL,
[ItemClassID] [int] NOT NULL,
[ItemClassCD] [nvarchar](30) NOT NULL,
[TRGItemClassCD] [nvarchar](30) NOT NULL,
CONSTRAINT [PK_EEdiDocType] PRIMARY KEY CLUSTERED
(
[CompanyID] ASC,
[ItemClassID] ASC,
[TRGItemClassCD] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
和DAC类:
[System.SerializableAttribute()]
public class AKTRGItemClassMap : PX.Data.IBqlTable
{
public abstract class itemClassID : IBqlField { }
[PXDBInt]
public virtual int? ItemClassID { get; set; }
public abstract class itemClassCD : IBqlField { }
[PXDBString(30, IsUnicode = true)]
public virtual string ItemClassCD { get; set; }
public abstract class trgItemClassCD : IBqlField { }
[PXDBString(30, IsUnicode = true)]
public virtual string TRGItemClassCD { get; set; }
}
有什么想法吗?
答案 0 :(得分:0)
我的问题的解决方案是使用PXLoginScope将诸如此类的任何图形实例创建和用法包装起来,以为其提供登录用户上下文。
using (var pxLoginScope = new PXLoginScope(userName, new string[0]))
{
var membershipUser = Membership.GetUser(pxLoginScope.UserName);
if (membershipUser != null)
{
pxLoginScope.UserName = membershipUser.UserName;
userName = PXContext.PXIdentity.User.Identity.Name;
if (pxLoginScope.CompanyName != null)
{
string[] rolesForUser = System.Web.Security.Roles.GetRolesForUser(pxLoginScope.UserName);
if (rolesForUser == null || rolesForUser.Length == 0)
throw new PXException("You are not allowed to login to the company {0}.", new object[1]
{
(object) pxLoginScope.CompanyName
});
else if (!Enumerable.Contains<string>((IEnumerable<string>)PXDatabase.AvailableCompanies,
pxLoginScope.CompanyName))
throw new PXException("You are not allowed to login to the company {0}.", new object[1]
{
(object) pxLoginScope.CompanyName
});
}
PXLogin.SetBranchID(pxLoginScope.UserName, pxLoginScope.CompanyName, pxLoginScope.Branch);
<graph creation and usage goes here>
}
}