0

在 Common Data Services SDKMicrosoft.CommonDataService中,我可以使用此代码从数据库中选择实体

// Specify the generic object to retrieve
var genericEntitySet = client.GetRelationalEntitySet(
    new EntitySetReference("Microsoft.CommonDataService.CommonEntities",
    AdvEntity.EntityName,
    Microsoft.CommonDataService.Version.Create("1.0.0")));

// Specify the required fields
var query = genericEntitySet.CreateQueryBuilder()
    .Project(pc => 
        pc
            .SelectField(f => f["PrimaryId"])
            .SelectField(f => f["Project_Title"])
            .SelectField(f => f["CreatedByUser"])
            .SelectField(f => f["CreatedOnDateTime"])
            .SelectField(f => f["LastModifiedByUser"])
            .SelectField(f => f["LastModifiedDateTime"])
            .SelectField(f => f["Opportuinity"])
            .SelectField(f => f["BNB"])
            .SelectField(f => f["SP_URL"])
            .SelectField(f => f["ProjectMgr"])
            .SelectField(f => f["WorkTeam"])
            .SelectField(f => f["BnB_ID"])
            .SelectField(f => f["Custodian"])
            .SelectField(f => f["Stage"])
            .SelectField(f => f["Opp_Status"])
            .SelectField(f => f["Confidential"])
            .SelectField(f => f["CRMT_Num"])
            .SelectField(f => f["Proj_Num"])
            .SelectField(f => f["Sector"])
            .SelectField(f => f["Service"])
            .SelectField(f => f["Archive"])
        );

var selectExecutor = client.CreateRelationalBatchExecuter(
    RelationalBatchExecutionMode.Transactional);

await selectExecutor
    .Query(query, out OperationResult<IReadOnlyList<RelationalEntity>> queryResult)
    .ExecuteAsync();

但是,必须为我可能需要检索的每种类型的对象选择所有这些字段似乎很麻烦。

有没有办法告诉代码获取所有属性

该文件指出

请注意,出于性能原因,没有自动选择所有字段的选项。

这个 SDK 是预览版,所以没有太多关于它的信息,但也许有人知道这个技巧?

4

2 回答 2

0

简史:您所说的 CDS 1.0 是建立在 Dynamics AX 之上的旧版本,现已退役。

基于 Dynamics CRM 又名 Dynamics 客户参与 (CE) 又名 Dynamics 365 的全新 CDS 2.0 称为应用程序 CDS。此应用程序 CDS 具有查询概念,例如 QueryExpression 和 FetchXML,您可以在其中提及所有属性 ( ColumnSet = new ColumnSet(true)) 以像 SQL ( select * from table)一样检索

var request = new RetrieveRequest()
{
  ColumnSet = new ColumnSet(true),
  RelatedEntitiesQuery = relationshipQueryCollection,
  Target = new EntityReference("account", accountid)
};

参考

从性能的角度来看,仍然不建议这样做。

于 2019-03-01T04:59:55.603 回答
-1

根据文档...

static async Task SimpleSelectAsync(Client client)
{
    var queryBuilder = client.GetRelationalEntitySet<ProductCategory>()
        .CreateQueryBuilder();

    var query = queryBuilder
        .Where(pc => pc.Name == "Electronics")
        .OrderByAscending(pc => new object[] { pc.CategoryId })
        .Project( /* REMOVE THIS STUFF?.. pc => pc.SelectField(f => f.CategoryId)
            .SelectField(f => f.Name)
            .SelectField(f => f.Description) */ );

    // Execute the query:
    OperationResult<IReadOnlyList<ProductCategory>> queryResult = null;
    var executor = client.CreateRelationalBatchExecuter(
        RelationalBatchExecutionMode.Transactional)
        .Query(query, out queryResult);

    await executor.ExecuteAsync();

    foreach (var pc in queryResult.Result)
    {
        Console.WriteLine(pc.Name);
    }
}
于 2018-03-06T06:04:05.250 回答