本文整理汇总了C#中QueryExpression.AddOrder方法的典型用法代码示例。如果您正苦于以下问题:C# QueryExpression.AddOrder方法的具体用法?C# QueryExpression.AddOrder怎么用?C# QueryExpression.AddOrder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QueryExpression
的用法示例。
在下文中一共展示了QueryExpression.AddOrder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: When_ordering_by_money_fields_descending_expected_result_is_returned
public void When_ordering_by_money_fields_descending_expected_result_is_returned()
{
List<Entity> contactList = new List<Entity>();
Entity contact1 = new Entity("contact");
contact1.Id = Guid.NewGuid();
contact1.Attributes["firstname"] = "Fred";
contact1.Attributes["lastname"] = "Bloggs";
contact1.Attributes["new_somefield"] = new Money(12345); // (decimal)678910
Entity contact2 = new Entity("contact");
contact2.Id = Guid.NewGuid();
contact2.Attributes["firstname"] = "Jo";
contact2.Attributes["lastname"] = "Bloggs";
contact2.Attributes["new_somefield"] = new Money(678910); // (decimal)678910
contactList.Add(contact2);
contactList.Add(contact1);
var context = new XrmFakedContext();
context.Initialize(contactList);
var service = context.GetFakedOrganizationService();
QueryExpression qry = new QueryExpression("contact");
qry.ColumnSet = new ColumnSet(true);
qry.AddOrder("new_somefield", OrderType.Descending);
var results = service.RetrieveMultiple(qry);
var firstResultValue = results.Entities[0]["new_somefield"] as Money;
Assert.Equal(678910M, firstResultValue.Value);
}
示例2: When_ordering_by_datetime_fields_expected_result_is_returned
public void When_ordering_by_datetime_fields_expected_result_is_returned()
{
List<Entity> contactList = new List<Entity>();
var now = DateTime.UtcNow;
Entity contact1 = new Entity("contact");
contact1.Id = Guid.NewGuid();
contact1.Attributes["firstname"] = "Fred";
contact1.Attributes["new_orderbyfield"] = now;
Entity contact2 = new Entity("contact");
contact2.Id = Guid.NewGuid();
contact2.Attributes["firstname"] = "Jo";
contact2.Attributes["new_orderbyfield"] = now.AddDays(1);
contactList.Add(contact2);
contactList.Add(contact1);
var context = new XrmFakedContext();
context.Initialize(contactList);
var service = context.GetFakedOrganizationService();
QueryExpression qry = new QueryExpression("contact");
qry.ColumnSet = new ColumnSet(true);
qry.AddOrder("new_orderbyfield", OrderType.Ascending);
var results = service.RetrieveMultiple(qry);
var firstResultValue = (DateTime)results.Entities[0]["new_orderbyfield"];
Assert.Equal(now, firstResultValue);
}
示例3: GetUsers
/// <summary>
/// Obtains all users corresponding to the search filter
/// </summary>
/// <param name="value">Search filter</param>
/// <returns>List of users matching the search filter</returns>
public List<Entity> GetUsers(string value)
{
var users = new List<Entity>();
var ceStatus = new ConditionExpression("isdisabled", ConditionOperator.Equal, false);
var feStatus = new FilterExpression();
feStatus.AddCondition(ceStatus);
var qe = new QueryExpression("systemuser");
qe.ColumnSet = new ColumnSet("systemuserid", "fullname", "lastname", "firstname", "domainname", "businessunitid");
qe.AddOrder("lastname", OrderType.Ascending);
qe.Criteria = new FilterExpression();
qe.Criteria.Filters.Add(new FilterExpression());
qe.Criteria.Filters[0].FilterOperator = LogicalOperator.And;
qe.Criteria.Filters[0].Filters.Add(feStatus);
qe.Criteria.Filters[0].Filters.Add(new FilterExpression());
qe.Criteria.Filters[0].Filters[1].FilterOperator = LogicalOperator.Or;
if (value.Length > 0)
{
bool isGuid = false;
try
{
Guid g = new Guid(value);
isGuid = true;
}
catch
{ }
if (isGuid)
{
var ce = new ConditionExpression("systemuserid", ConditionOperator.Equal, value);
qe.Criteria.Filters[0].Filters[1].AddCondition(ce);
}
else
{
var ce = new ConditionExpression("fullname", ConditionOperator.Like, value.Replace("*", "%"));
var ce2 = new ConditionExpression("firstname", ConditionOperator.Like, value.Replace("*", "%"));
var ce3 = new ConditionExpression("lastname", ConditionOperator.Like, value.Replace("*", "%"));
var ce4 = new ConditionExpression("domainname", ConditionOperator.Like, value.Replace("*", "%"));
qe.Criteria.Filters[0].Filters[1].AddCondition(ce);
qe.Criteria.Filters[0].Filters[1].AddCondition(ce2);
qe.Criteria.Filters[0].Filters[1].AddCondition(ce3);
qe.Criteria.Filters[0].Filters[1].AddCondition(ce4);
}
}
foreach (var record in service.RetrieveMultiple(qe).Entities)
{
users.Add(record);
}
return users;
}
示例4: LoadViews
internal void LoadViews(Action action)
{
this.host.WorkAsync("Loading views...",
(a) =>
{
this.views = new Dictionary<string, List<Entity>>();
if (views.Count == 0)
{
var combinedResult = new Dictionary<string, DataCollection<Entity>>();
DataCollection<Entity> singleResult;
var qex = new QueryExpression();
qex.ColumnSet = new ColumnSet("name", "returnedtypecode", "fetchxml", "layoutxml");
qex.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0);
qex.Criteria.AddCondition("querytype", ConditionOperator.In, 0, 32);
qex.AddOrder("name", OrderType.Ascending);
foreach (var entity in new string[] { "savedquery", "userquery" })
{
qex.EntityName = entity;
singleResult = this.host.Service.RetrieveMultiple(qex).Entities;
if (singleResult.Count > 0)
{
combinedResult.Add(qex.EntityName, singleResult);
}
}
a.Result = combinedResult;
}
},
(a) =>
{
var allViews = (Dictionary<string, DataCollection<Entity>>)a.Result;
foreach (var key in allViews.Keys)
{
this.ExtractViews(allViews[key]);
}
this.entities = this.views.Keys.Select(x => x.Split('|')[0]).Distinct().ToList();
action();
});
}
示例5: LoadViews
internal void LoadViews(Action viewsLoaded)
{
if (working)
{
return;
}
if (entities == null || entities.Count == 0)
{
LoadEntities(viewsLoaded);
return;
}
working = true;
WorkAsync("Loading views...",
(bgworker, workargs) =>
{
EnableControls(false);
if (views == null || views.Count == 0)
{
if (Service == null)
{
throw new Exception("Need a connection to load views.");
}
var qex = new QueryExpression("savedquery");
qex.ColumnSet = new ColumnSet("name", "returnedtypecode", "fetchxml");
qex.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0);
qex.Criteria.AddCondition("querytype", ConditionOperator.In, 0, 32);
qex.AddOrder("name", OrderType.Ascending);
bgworker.ReportProgress(33, "Loading system views...");
var sysviews = Service.RetrieveMultiple(qex);
foreach (var view in sysviews.Entities)
{
var entityname = view["returnedtypecode"].ToString();
if (!string.IsNullOrWhiteSpace(entityname) && entities.ContainsKey(entityname))
{
if (views == null)
{
views = new Dictionary<string, List<Entity>>();
}
if (!views.ContainsKey(entityname + "|S"))
{
views.Add(entityname + "|S", new List<Entity>());
}
views[entityname + "|S"].Add(view);
}
}
qex.EntityName = "userquery";
bgworker.ReportProgress(66, "Loading user views...");
var userviews = Service.RetrieveMultiple(qex);
foreach (var view in userviews.Entities)
{
var entityname = view["returnedtypecode"].ToString();
if (!string.IsNullOrWhiteSpace(entityname) && entities.ContainsKey(entityname))
{
if (views == null)
{
views = new Dictionary<string, List<Entity>>();
}
if (!views.ContainsKey(entityname + "|U"))
{
views.Add(entityname + "|U", new List<Entity>());
}
views[entityname + "|U"].Add(view);
}
}
bgworker.ReportProgress(100, "Finalizing...");
}
},
(completedargs) =>
{
working = false;
EnableControls(true);
if (completedargs.Error != null)
{
MessageBox.Show(completedargs.Error.Message);
}
else
{
viewsLoaded();
}
},
(changeargs) =>
{
SetWorkingMessage(changeargs.UserState.ToString());
});
}
示例6: BuildQueryActive
public static QueryExpression BuildQueryActive(string entityType, IEnumerable<string> fields,
IEnumerable<ConditionExpression> filters, string[] sortFields)
{
var query = new QueryExpression(entityType);
query.Criteria.AddCondition("statecode", ConditionOperator.Equal, XrmPicklists.State.Active);
if (filters != null)
{
foreach (var condition in filters)
query.Criteria.AddCondition(condition);
}
if (sortFields != null)
{
foreach (var sortField in sortFields)
query.AddOrder(sortField, OrderType.Ascending);
}
if (fields != null)
query.ColumnSet = new ColumnSet(fields.ToArray());
else
query.ColumnSet = new ColumnSet(true);
return query;
}
示例7: BuildQuery
public static QueryExpression BuildQuery(string entityType, IEnumerable<string> fields,
IEnumerable<ConditionExpression> filters, IEnumerable<string> sortFields)
{
var query = new QueryExpression(entityType);
if (filters != null)
{
foreach (var condition in filters)
query.Criteria.AddCondition(condition);
}
if (sortFields != null)
{
foreach (var sortField in sortFields)
query.AddOrder(sortField, OrderType.Ascending);
}
if (fields != null)
query.ColumnSet = new ColumnSet(fields.ToArray());
else
query.ColumnSet = new ColumnSet(true);
return query;
}
示例8: AddOrderExpressions
private static void AddOrderExpressions(QueryExpression query, IEnumerable<OrderExpression> orders)
{
if (orders != null)
{
foreach (var order in orders)
query.AddOrder(order.AttributeName, order.OrderType);
}
}
示例9: lastActivity
protected DateTime lastActivity(string username, string subject)
{
using (OrganizationService service = new OrganizationService(OurConnect()))
{
ConditionExpression toCondition = new ConditionExpression();
ConditionExpression fromCondition = new ConditionExpression();
ConditionExpression subjectCondition = new ConditionExpression();
toCondition.AttributeName = consts.to;
toCondition.Operator = ConditionOperator.Equal;
toCondition.Values.Add(username);
fromCondition.AttributeName = consts.from;
fromCondition.Operator = ConditionOperator.Equal;
fromCondition.Values.Add(_ApplicationName);
FilterExpression filter = new FilterExpression();
filter.Conditions.Add(toCondition);
filter.Conditions.Add(fromCondition);
if (subject != String.Empty)
{
subjectCondition.AttributeName = consts.subject;
subjectCondition.Operator = ConditionOperator.Equal;
subjectCondition.Values.Add(subject);
}
QueryExpression query = new QueryExpression(consts.activities);
query.ColumnSet.AddColumn(consts.activitytime);
query.AddOrder(consts.activitytime, OrderType.Descending);
query.Criteria.AddFilter(filter);
EntityCollection collection = service.RetrieveMultiple(query);
return (DateTime)collection.Entities[0][consts.activitytime];
}
}
示例10: getWorkflows
private void getWorkflows()
{
#region Reset Variables
ExecutionRecordSet.Entities.Clear();
_workflows.Entities.Clear();
_selectedWorkflow = null;
_views.Entities.Clear();
_selectedView = null;
this.Invoke((MethodInvoker)delegate()
{
cmbWorkflows.Items.Clear();
cmbViews.Items.Clear();
txtRecordCount.Clear();
rtxtFetchXML.Clear();
radFetchXML.Checked = false;
radViews.Checked = true;
//progressBar1.Style = ProgressBarStyle.Marquee;
txtBatch.Text = "200";
emrBatchSize = 200;
});
#endregion Reset Variables
#region Get Workflows Query
QueryExpression query = new QueryExpression("workflow");
query.ColumnSet.AddColumns("workflowid", "name", "primaryentity");
query.Distinct = true;
query.AddOrder("name", OrderType.Ascending);
query.Criteria = new FilterExpression();
//query.Criteria.AddCondition("category", ConditionOperator.Equal, 0);
FilterExpression childFilter = query.Criteria.AddFilter(LogicalOperator.And);
childFilter.AddCondition("category", ConditionOperator.Equal, 0);
childFilter.AddCondition("activeworkflowid", ConditionOperator.NotNull);
childFilter.AddCondition("ondemand", ConditionOperator.Equal, true);
_workflows = service.RetrieveMultiple(query);
if (_workflows.Entities.Count > 0)
{
foreach (var item in _workflows.Entities)
{
this.Invoke((MethodInvoker)delegate()
{
cmbWorkflows.Items.Add(item["name"]);
});
}
}
this.Invoke((MethodInvoker)delegate()
{
cmbWorkflows.Text = "Select a Workflow to run";
cmbViews.Text = "Select a Workflow to populate this list";
//progressBar1.Style = ProgressBarStyle.Continuous;
});
infoPanel.Dispose();
infoPanel.Dispose();
Controls.Remove(infoPanel);
#endregion Get Workflows Query
}
示例11: LoadAssemblies
private Task<List<Assembly>> LoadAssemblies()
{
return Task.Run(() =>
{
var query = new QueryExpression("pluginassembly");
query.Distinct = true;
query.NoLock = true;
query.ColumnSet = new ColumnSet("name", "pluginassemblyid");
query.AddOrder("name", OrderType.Ascending);
var type = query.AddLink("plugintype", "pluginassemblyid", "pluginassemblyid", JoinOperator.Inner);
type.LinkCriteria.AddCondition("typename", ConditionOperator.NotLike, "Microsoft.Crm.%");
type.LinkCriteria.AddCondition("typename", ConditionOperator.NotLike, "ActivityFeeds.%");
var result = _service.RetrieveMultiple(query);
var assemblies = result.Entities.Select(e => new Assembly
{
AssemblyId = e.Id,
Export = false,
Name = e["name"] as string,
RegisteredStepCount = 0
}).ToList();
foreach (var assembly in assemblies)
{
query = new QueryExpression("sdkmessageprocessingstep");
query.Distinct = true;
query.NoLock = true;
query.ColumnSet = new ColumnSet("sdkmessageprocessingstepid");
type = query.AddLink("plugintype", "plugintypeid", "plugintypeid");
type.LinkCriteria.AddCondition("pluginassemblyid", ConditionOperator.Equal, assembly.AssemblyId);
result = _service.RetrieveMultiple(query);
assembly.RegisteredStepCount = result.Entities.Count;
}
return assemblies;
});
}
示例12: Get
public static IEnumerable<Entity> Get(
this IOrganizationService service,
out int totalItemsCount,
string entityname,
bool allattributes = false,
IEnumerable<OrderBy> orders = null,
IEnumerable<ConditionExpression> conditions = null,
IEnumerable<string> attrs = null,
int? page = null,
int? count = null)
{
ObjectCacheManager.GetInstance().Clear();
if (string.IsNullOrEmpty(entityname)) throw new ArgumentNullException("entityname");
var query = new QueryExpression(entityname);
if (attrs != null)
{
var a = attrs.ToArray();
if (allattributes)
{
query.ColumnSet = new ColumnSet(true);
}
else
{
query.ColumnSet = a.Count() == 0 ? new ColumnSet(false) : new ColumnSet(a);
}
}
if (conditions != null)
{
conditions.ToList().ForEach(x => { query.Criteria.AddCondition(x); });
}
if (orders != null)
{
orders.ToList().ForEach(x => { query.AddOrder(x.AttributeName, x.OrderType); });
}
List<Entity> ents;
totalItemsCount = 0;
if (page != null && count != null)
{
query.PageInfo = new PagingInfo
{
Count = count.Value,
PageNumber = page.Value,
PagingCookie = null,
ReturnTotalRecordCount = true
};
ents = service.GetPage(query, out totalItemsCount);
}
else
{
ents = service.GetAllEntities(query);
}
return ents;
}
示例13: When_ordering_by_guid_fields_expected_result_is_returned
public void When_ordering_by_guid_fields_expected_result_is_returned()
{
List<Entity> contactList = new List<Entity>();
var g1 = new Guid(12, 0, 0, new byte[] { new byte(), new byte(), new byte(), new byte(),
new byte(), new byte(), new byte(), new byte() });
var g2 = new Guid(24, 0, 0, new byte[] { new byte(), new byte(), new byte(), new byte(),
new byte(), new byte(), new byte(), new byte() });
Entity contact1 = new Entity("contact");
contact1.Id = Guid.NewGuid();
contact1.Attributes["firstname"] = "Fred";
contact1.Attributes["new_orderbyfield"] = g1;
Entity contact2 = new Entity("contact");
contact2.Id = Guid.NewGuid();
contact2.Attributes["firstname"] = "Jo";
contact2.Attributes["new_orderbyfield"] = g2;
contactList.Add(contact2);
contactList.Add(contact1);
var context = new XrmFakedContext();
context.Initialize(contactList);
var service = context.GetFakedOrganizationService();
QueryExpression qry = new QueryExpression("contact");
qry.ColumnSet = new ColumnSet(true);
qry.AddOrder("new_orderbyfield", OrderType.Ascending);
var results = service.RetrieveMultiple(qry);
var firstResultValue = (Guid)results.Entities[0]["new_orderbyfield"];
Assert.Equal(g1, firstResultValue);
}
示例14: LocalCrmTests_OrderBy
public void LocalCrmTests_OrderBy()
{
var service = GetService();
service.Create(new Contact() {FirstName = "Chuck", LastName = "Adams"});
service.Create(new Contact() {FirstName = "Anna", LastName = "Adams"});
service.Create(new Contact() {FirstName = "Bill", LastName = "Adams"});
var qe = new QueryExpression(Contact.EntityLogicalName);
qe.ColumnSet = new ColumnSet(true);
// Ascending Order Test
qe.AddOrder("firstname", OrderType.Ascending);
var results = service.GetEntities<Contact>(qe);
Assert.AreEqual("Anna", results[0].FirstName, "Ascending Ordering failed. \"Anna\" should have been returned first");
Assert.AreEqual("Bill", results[1].FirstName, "Ascending Ordering failed. \"Bill\" should have been returned second");
Assert.AreEqual("Chuck", results[2].FirstName, "Ascending Ordering failed. \"Chuck\" should have been returned third");
// Descending Order Test
qe.Orders[0].OrderType = OrderType.Descending;
results = service.GetEntities<Contact>(qe);
Assert.AreEqual("Chuck", results[0].FirstName, "Descending Ordering failed. \"Chuck\" should have been returned first");
Assert.AreEqual("Bill", results[1].FirstName, "Descending Ordering failed. \"Bill\" should have been returned second");
Assert.AreEqual("Anna", results[2].FirstName, "Descending Ordering failed. \"Anna\" should have been returned third");
// Add Dups
service.Create(new Contact() {FirstName = "Chuck", LastName = "Bell"});
service.Create(new Contact() {FirstName = "Anna", LastName = "Bell"});
service.Create(new Contact() {FirstName = "Anna", LastName = "Carter"});
service.Create(new Contact() {FirstName = "Bill", LastName = "Bell"});
service.Create(new Contact() {FirstName = "Bill", LastName = "Carter"});
service.Create(new Contact() {FirstName = "Chuck", LastName = "Carter"});
// Order By Descending First Then By Ascending Last Test
qe.AddOrder("lastname", OrderType.Ascending);
results = service.GetEntities<Contact>(qe);
Assert.AreEqual("Chuck Adams", results[0].FullName, "Descending then Ascending Ordering failed. \"Chuck Adams\" should have been returned first");
Assert.AreEqual("Chuck Bell", results[1].FullName, "Descending then Ascending Ordering failed. \"Chuck Bell\" should have been returned second");
Assert.AreEqual("Chuck Carter", results[2].FullName, "Descending then Ascending Ordering failed. \"Chuck Carter\" should have been returned third");
Assert.AreEqual("Bill Adams", results[3].FullName, "Descending then Ascending Ordering failed. \"Bill Adams\" should have been returned forth");
Assert.AreEqual("Bill Bell", results[4].FullName, "Descending then Ascending Ordering failed. \"Bill Bell\" should have been returned fifth");
Assert.AreEqual("Bill Carter", results[5].FullName, "Descending then Ascending Ordering failed. \"Bill Carter\" should have been returned sixth");
Assert.AreEqual("Anna Adams", results[6].FullName, "Descending then Ascending Ordering failed. \"Anna Adams\" should have been returned seventh");
Assert.AreEqual("Anna Bell", results[7].FullName, "Descending then Ascending Ordering failed. \"Anna Bell\" should have been returned eighth");
Assert.AreEqual("Anna Carter", results[8].FullName, "Descending then Ascending Ordering failed. \"Anna Carter\" should have been returned nineth");
// Order By Ascending First Then By Descending Last Test
qe.Orders.Clear();
qe.AddOrder("firstname", OrderType.Ascending);
qe.AddOrder("lastname", OrderType.Descending);
results = service.GetEntities<Contact>(qe);
Assert.AreEqual("Anna Carter", results[0].FullName, "Ascending then Descending Ordering failed. \"Anna Carter\" should have been returned first");
Assert.AreEqual("Anna Bell", results[1].FullName, "Ascending then Descending Ordering failed. \"Anna Bell\" should have been returned second");
Assert.AreEqual("Anna Adams", results[2].FullName, "Ascending then Descending Ordering failed. \"Anna Adams\" should have been returned thrid");
Assert.AreEqual("Bill Carter", results[3].FullName, "Ascending then Descending Ordering failed. \"Bill Carter\" should have been returned forth");
Assert.AreEqual("Bill Bell", results[4].FullName, "Ascending then Descending Ordering failed. \"Bill Bell\" should have been returned fifth");
Assert.AreEqual("Bill Adams", results[5].FullName, "Ascending then Descending Ordering failed. \"Bill Adams\" should have been returned sixth");
Assert.AreEqual("Chuck Carter", results[6].FullName, "Ascending then Descending Ordering failed. \"Chuck Carter\" should have been returned seventh");
Assert.AreEqual("Chuck Bell", results[7].FullName, "Ascending then Descending Ordering failed. \"Chuck Bell\" should have been returned eighth");
Assert.AreEqual("Chuck Adams", results[8].FullName, "Ascending then Descending Ordering failed. \"Chuck Adams\" should have been returned nineth");
// Order by Date Ascending
qe.Orders.Clear();
qe.AddOrder("createdon", OrderType.Ascending);
results = service.GetEntities<Contact>(qe);
Assert.AreEqual("Adams", results[0].LastName, "Ascending Date Ordering failed. \"Adams\" should have been returned first");
Assert.AreEqual("Adams", results[1].LastName, "Ascending Date Ordering failed. \"Adams\" should have been returned first");
Assert.AreEqual("Adams", results[2].LastName, "Ascending Date Ordering failed. \"Adams\" should have been returned first");
// Order by Date Descending
qe.Orders.Clear();
qe.AddOrder("createdon", OrderType.Descending);
results = service.GetEntities<Contact>(qe);
Assert.AreEqual("Adams", results[8].LastName, "Ascending Date Ordering failed. \"Adams\" should have been returned last");
Assert.AreEqual("Adams", results[7].LastName, "Ascending Date Ordering failed. \"Adams\" should have been returned last");
Assert.AreEqual("Adams", results[6].LastName, "Ascending Date Ordering failed. \"Adams\" should have been returned last");
}
示例15: LoadRoles
private Task<List<Role>> LoadRoles()
{
return Task.Run(() =>
{
var query = new QueryExpression("role");
query.NoLock = true;
query.ColumnSet = new ColumnSet("name", "roleid");
query.AddOrder("name", OrderType.Ascending);
var bu = query.AddLink("businessunit", "businessunitid", "businessunitid");
bu.LinkCriteria.AddCondition("parentbusinessunitid", ConditionOperator.Null);
var result = _service.RetrieveMultiple(query);
var roles = result.Entities.Select(e => new Role
{
RoleId = e.Id,
Name = e["name"] as string
});
roles = roles.Concat(new Role[] {
new Role
{
RoleId = Guid.Empty,
Name = " -- Users without an assigned role -- "
}
});
return roles.OrderBy(r => r.Name).ToList();
});
}