0

In the Common Data Services SDK Microsoft.CommonDataService, I can select entities from the db with this code

// 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();

However, it seems cumbersome to have to select all those fields for every type of object I may need to retrieve.

Is there a way of just telling the code to get all properties?

The documentation states that

Note that, for performance reasons, there is no option to automatically select all fields.

This SDK is in preview and so there is not much information around about it, but perhaps someone knows a trick for this?

Bassie
  • 9,529
  • 8
  • 68
  • 159

2 Answers2

0

A brief history: CDS 1.0 which you are talking about is old version built on top of Dynamics AX is retired now.

A brand new CDS 2.0 built on top of Dynamics CRM aka Dynamics customer engagement (CE) aka Dynamics 365 called CDS for apps. This CDS for apps has querying concepts like QueryExpression & FetchXML where you can mention all attributes (ColumnSet = new ColumnSet(true)) to retrieve just like SQL ( select * from table )

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

Reference

Still this is not recommended from performance perspective.

-1

As per the documentation...

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);
    }
}
Adam Cox
  • 3,341
  • 1
  • 36
  • 46
  • The `Project()` method requires a parameter. When calling as you suggest I get `There is no argument given that corresponds to the required formal parameter 'project' of 'WhereClauseBuilder.Project(Func, RelatedEntityIncludeBuilder>)'`. Where in the documentation did you find that example? I can't see it – Bassie Mar 06 '18 at 22:35