Acumatica中PXDBScalar报错:uniqueidentifier与int类型不兼容
解决Acumatica中PXDBScalar的类型兼容错误
我之前在Acumatica开发中也碰到过一模一样的问题,咱们直接说根源和解决方案:
问题原因
你用Like<OtherIDAttr>来匹配属性ID,但这里有两个核心问题:
- 操作符误用:你要匹配的是精确的attributeID值"OTHERID",
Like是模糊匹配操作符,用在这里完全没必要。 - 类型推断冲突:Acumatica的BQL对
Like操作的类型校验逻辑比较严格,当搭配Constant<string>使用时,容易触发隐式类型转换错误,导致系统误判CSAnswers.refNoteID(uniqueidentifier类型)和条件值的类型不兼容,最终抛出"uniqueidentifier与int类型不兼容"的报错。
解决方案
把Like<OtherIDAttr>替换成Equal<OtherIDAttr>即可,因为我们要做的是精确匹配属性ID。修正后的完整代码如下:
public class CustomerExt : PXCacheExtension<Customer> { #region OtherID [PXString] [PXUIField(DisplayName = "Other ID")] [PXDBScalar(typeof(Search<CSAnswers.value, Where<CSAnswers.refNoteID, Equal<Current<Customer.noteID>>, And<CSAnswers.attributeID, Equal<OtherIDAttr>>>>))] public virtual string UsrOtherID { get; set; } public abstract class usrOtherID : IBqlField { } #endregion public class OtherIDAttr: Constant<string> { public OtherIDAttr() : base("OTHERID") { } } }
额外说明
如果以后确实需要模糊匹配属性ID(比如匹配以"OTHER"开头的属性),那需要在Constant中加入通配符,同时确保类型严格匹配,示例如下:
public class OtherIDAttr: Constant<string> { public OtherIDAttr() : base("OTHER%") { } }
此时再用Like<OtherIDAttr>就不会有类型问题了,但回到你的场景,精确匹配用Equal才是最合理的选择。
内容的提问来源于stack exchange,提问作者nicksurname
相关产品推荐
相关产品推荐

