这是AcumaticaERP特有的。我创建了一个如下所示的BaseBlcHelper类:
char *
我创建了此类,是因为我想可以在其中添加一些共享功能。
这是问题。当我有这样的选择语句时:
public abstract class BaseBlcHelper<TBlcObject, TDacObject> :
PXGraph<TBlcObject>,
IBaseBlcHelper<TDacObject, TDacObject> where TBlcObject : PXGraph
where TDacObject : class, IBqlTable, new()
您如何将TDacObject(通用)对象解析为查询的“ Vendor.vendor1099”部分,依此类推?
答案 0 :(得分:0)
我假定您将创建将DAC Field参数作为通用类型的Helper方法。
这是一个示例原型,它以通用图,DAC类型,字段类型和字段值作为参数:
public static List<TDacObject> Select<TFieldObject>(this PXGraph graph, object fieldParamValue)
where TFieldObject : class,IBqlField
where TDacObject : class,IBqlTable
{
// 'graph' will be used to provide the required context for query execution
// 'TDacObject' is a generic DAC type used in the query
// 'TFieldObject' is a generic DAC type used in the query
// 'fieldParamValue' is a generic value you can use in your query
}
使用泛型类型制作和执行查询的技巧是使用泛型类型创建BQLCommand对象。之后,您可以创建一个以BQLCommand作为输入参数的PXView对象。最后,您可以执行PXView的Select方法来执行BQL查询。
以下是一些通用的按ID选择方法的示例代码。它应该使您对该过程有基本了解:
// Roughly equivalent to:
// PXSelect<TDacObject, Where<TDacObject.TDacField, Equals<Required<fieldParamValue>>>>
// TDacObject below is extracted from the type 'fieldType.DeclaringType'
// You can substitute that for your generic DAC Type entity
public static List<T> SelectById<T, TField>(this PXGraph graph, object id)
where TField : class, IBqlField
where T : class, IBqlTable
{
return SelectById(graph, typeof(TField), id).Cast<T>().ToList();
}
public static List<object> SelectById(this PXGraph graph, Type fieldType, object id)
{
var select = CreateSelectCommand(fieldType);
var view = GetView(graph, fieldType, select);
return view.SelectMulti(id);
}
public static BqlCommand CreateSelectCommand(Type fieldType)
{
return CreateSelectCommand(fieldType.DeclaringType, fieldType);
}
public static BqlCommand CreateSelectCommand(Type entityType, Type fieldType)
{
Type required = BqlCommand.Compose(typeof(Required<>), fieldType);
Type equal = BqlCommand.Compose(typeof(Equal<>), required);
Type where = BqlCommand.Compose(typeof(Where<,>), fieldType, equal);
return BqlCommand.CreateInstance(typeof(Select<,>), entityType, where);
}
public static PXView GetView(this PXGraph graph, Type fieldType, BqlCommand select)
{
PXView view;
graph.Views.TryGetValue(fieldType.FullName, out view);
if (view == null)
{
view = new PXView(graph, false, @select);
graph.Views.Add(fieldType.FullName, view);
graph.EnsureCachePersistence(fieldType.DeclaringType);
}
return view;
}