Skip to content

Instantly share code, notes, and snippets.

@islaytitans
Last active February 27, 2016 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save islaytitans/78485d71954b09d29901 to your computer and use it in GitHub Desktop.
Save islaytitans/78485d71954b09d29901 to your computer and use it in GitHub Desktop.
How to query data from xDB from facets
public class GetSampleOrders : ReportProcessorBase
{
private readonly QueryBuilder _contactsQueryBuilder = new QueryBuilder()
{
collectionName = "Contacts", // Name of the collection containing contacts in MongoDb
QueryParms =
{
{ "_id", "@contactid" },
},
Fields =
{
"_id",
"KeyInteractions_SampleOrder", // path so the Sample Order Element in our custom xDB Facet
"System_VisitCount"
}
};
public override void Process(ReportProcessorArgs args)
{
Guid contactId = args.ReportParameters.ContactId;
DataTable contactQueryExpression =
base.GetTableFromContactQueryExpression(_contactsQueryBuilder.Build(), contactId, new Guid?());
Assert.IsTrue(contactQueryExpression.Rows.Count >= 1,
string.Format("Contact with id {0} was not found.", (object) contactId));
int? nullable = DataRowExtensions.Field<int?>(contactQueryExpression.Rows[0], "System_VisitCount");
if (nullable == null)
Log.Debug(string.Format("No VisitCount exists for contact: {0}", (object) contactId));
args.QueryResult = contactQueryExpression;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment