var query = new QueryExpression("new_ord_billing");
/// 分页参数设置
PagingInfo pageInfo = new PagingInfo();
pageInfo.Count = 20;
pageInfo.PageNumber = 1;
// 返回TotalRecordCount(数据总条数)时设置为true 否则TotalRecordCount会返回-1
pageInfo.ReturnTotalRecordCount = true;
query.PageInfo = pageInfo;
var shipNos = new string[] { "2019112824", "2020081805" };
// 查询条件设置
query.Criteria.AddCondition(new ConditionExpression("new_name", ConditionOperator.In, shipNos));
query.Criteria.AddCondition("new_type", ConditionOperator.Equal, 1);
FilterExpression filterOr = new FilterExpression
{
FilterOperator = LogicalOperator.Or,
Filters =
{
new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression("modifiedon", ConditionOperator.OnOrAfter, DateTime.Now.AddDays(-1).ToShortDateString())
}
},
new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression("createdon", ConditionOperator.On, DateTime.Now.ToShortDateString()),
}
}
}
};
query.Criteria.Filters.Add(filterOr);
query.ColumnSet = new ColumnSet(
"new_bill_type",
"new_amount",
"new_account_id",
"createdon",
"new_type",
"new_financial_month",
"new_discount"
);
// 获取全部字段
// query.ColumnSet = new ColumnSet(true)
// 连接查询
query.LinkEntities.Add(new LinkEntity("new_ord_billing", "account", "new_account_id", "accountid", JoinOperator.LeftOuter));
query.LinkEntities[0].Columns.AddColumn("new_erp_number");
query.LinkEntities[0].EntityAlias = "ac";
query.LinkEntities[0].LinkCriteria.AddCondition("new_erp_number", ConditionOperator.Like, "%" + "CD001" + "%");
// 查询数据
var ec = OrganizationService.RetrieveMultiple(query);
if (ec != null && ec.Entities.Count > 0)
{
// ec.TotalRecordCount获取数据总条数
foreach (var entity in ec.Entities)
{
ReturnModel model = new ReturnModel();
// 单行文本
model.BillType = entity.GetAttributeValue<string>("new_bill_type");
// 货币类型
if (entity.Contains("new_amount"))
{
model.Amount = entity.GetAttributeValue<Money>("new_amount").Value.ToString();
}
// 查找
if (entity.GetAttributeValue<EntityReference>("new_account_id") != null)
{
model.AccountName = entity.GetAttributeValue<EntityReference>("new_account_id").Name;
}
// 连接查询获取
if (entity.Attributes.Keys.Contains("ac.new_erpnumber") == true)
{
model.ErpNumber = ((AliasedValue)entity["ac.new_erpnumber"]).Value.ToString();
}
// 日期和时间
model.CreatedOn = entity.GetAttributeValue<DateTime>("createdon").ToString();
// 选项集
if (entity.Contains("new_type"))
{
model.Type = entity.GetAttributeValue<OptionSetValue>("new_type").Value;
}
// 整数
model.FinancialMonth = entity.GetAttributeValue<int>("new_financial_month");
// 十进制数
model.Discount = entity.GetAttributeValue<decimal>("new_discount");
}
}
using System;
using Microsoft.Xrm.Sdk.Query;
using System.Collections.Generic;
using Microsoft.Xrm.Sdk;
using Newtonsoft.Json;
ConditionOperator
using System.Runtime.Serialization;
namespace Microsoft.Xrm.Sdk.Query
{
//
// 摘要:
// Describes the type of comparison for two values (or expressions) in a condition
// expression.
[DataContract(Name = "ConditionOperator", Namespace = "http://schemas.microsoft.com/xrm/2011/Contracts")]
public enum ConditionOperator
{
//
// 摘要:
// The values are compared for equality. Value = 0.
[EnumMember]
Equal,
//
// 摘要:
// The two values are not equal. Value = 1.
[EnumMember]
NotEqual,
//
// 摘要:
// The value is greater than the compared value. Value = 2.
[EnumMember]
GreaterThan,
//
// 摘要:
// The value is less than the compared value. Value = 3.
[EnumMember]
LessThan,
//
// 摘要:
// The value is greater than or equal to the compared value. Value = 4.
[EnumMember]
GreaterEqual,
//
// 摘要:
// The value is less than or equal to the compared value. Value = 5.
[EnumMember]
LessEqual,
//
// 摘要:
// The character string is matched to the specified pattern. Value = 6.
[EnumMember]
Like,
//
// 摘要:
// The character string does not match the specified pattern. Value = 7.
[EnumMember]
NotLike,
//
// 摘要:
// TheThe value exists in a list of values. Value = 8.
[EnumMember]
In,
//
// 摘要:
// The given value is not matched to a value in a subquery or a list. Value = 9.
[EnumMember]
NotIn,
//
// 摘要:
// The value is between two values. Value = 10.
[EnumMember]
Between,
//
// 摘要:
// The value is not between two values. Value = 11.
[EnumMember]
NotBetween,
//
// 摘要:
// The value is null. Value = 12.
[EnumMember]
Null,
//
// 摘要:
// The value is not null. Value = 13.
[EnumMember]
NotNull,
//
// 摘要:
// The value equals yesterday’s date. Value = 14.
[EnumMember]
Yesterday,
//
// 摘要:
// The value equals today’s date. Value = 15.
[EnumMember]
Today,
//
// 摘要:
// The value equals tomorrow’s date. Value = 16.
[EnumMember]
Tomorrow,
//
// 摘要:
// The value is within the last seven days including today. Value = 17.
[EnumMember]
Last7Days,
//
// 摘要:
// The value is within the next seven days. Value = 18.
[EnumMember]
Next7Days,
//
// 摘要:
// The value is within the previous week including Sunday through Saturday. Value
// = 19.
[EnumMember]
LastWeek,
//
// 摘要:
// The value is within the current week. Value = 20.
[EnumMember]
ThisWeek,
//
// 摘要:
// The value is within the next week. Value = 21.
[EnumMember]
NextWeek,
//
// 摘要:
// The value is within the last month including first day of the last month and
// last day of the last month. Value = 22.
[EnumMember]
LastMonth,
//
// 摘要:
// The value is within the current month. Value = 23.
[EnumMember]
ThisMonth,
//
// 摘要:
// The value is within the next month. Value = 24.
[EnumMember]
NextMonth,
//
// 摘要:
// The value is on a specified date. Value = 25.
[EnumMember]
On,
//
// 摘要:
// The value is on or before a specified date. Value = 26.
[EnumMember]
OnOrBefore,
//
// 摘要:
// The value is on or after a specified date. Value = 27.
[EnumMember]
OnOrAfter,
//
// 摘要:
// The value is within the previous year. Value = 28.
[EnumMember]
LastYear,
//
// 摘要:
// The value is within the current year. Value = 29.
[EnumMember]
ThisYear,
//
// 摘要:
// The value is within the next year. Value = 30.
[EnumMember]
NextYear,
//
// 摘要:
// The value is within the last X hours. Value =31.
[EnumMember]
LastXHours,
//
// 摘要:
// The value is within the next X (specified value) hours. Value = 32.
[EnumMember]
NextXHours,
//
// 摘要:
// The value is within last X days. Value = 33.
[EnumMember]
LastXDays,
//
// 摘要:
// The value is within the next X (specified value) days. Value = 34.
[EnumMember]
NextXDays,
//
// 摘要:
// The value is within the last X (specified value) weeks. Value = 35.
[EnumMember]
LastXWeeks,
//
// 摘要:
// The value is within the next X weeks. Value = 36.
[EnumMember]
NextXWeeks,
//
// 摘要:
// The value is within the last X (specified value) months. Value = 37.
[EnumMember]
LastXMonths,
//
// 摘要:
// The value is within the next X (specified value) months. Value = 38.
[EnumMember]
NextXMonths,
//
// 摘要:
// The value is within the last X years. Value = 39.
[EnumMember]
LastXYears,
//
// 摘要:
// The value is within the next X years. Value = 40.
[EnumMember]
NextXYears,
//
// 摘要:
// The value is equal to the specified user ID. Value = 41.
[EnumMember]
EqualUserId,
//
// 摘要:
// The value is not equal to the specified user ID. Value = 42.
[EnumMember]
NotEqualUserId,
//
// 摘要:
// The value is equal to the specified business ID. Value = 43.
[EnumMember]
EqualBusinessId,
//
// 摘要:
// The value is not equal to the specified business ID. Value = 44.
[EnumMember]
NotEqualBusinessId,
//
// 摘要:
// No token name is specified <token xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">
// <?Comment AL: Bug fix 5/30/12 2012-05-30T11:03:00Z Id='2?>internal<?CommentEnd
// Id='2' ?></token>.
[EnumMember]
ChildOf,
//
// 摘要:
// The value is found in the specified bit-mask value. Value = 46.
[EnumMember]
Mask,
//
// 摘要:
// The value is not found in the specified bit-mask value. Value = 47.
[EnumMember]
NotMask,
//
// 摘要:
// For internal use only. Value = 48.
[EnumMember]
MasksSelect,
//
// 摘要:
// The string contains another string. Value = 49.
// You must use the Contains operator for only those attributes that are enabled
// for full-text indexing. Otherwise, you will receive a generic SQL error message
// while retrieving data. In a Microsoft Dynamics 365 default installation, only
// the attributes of the KBArticle (article) entity are enabled for full-text indexing.
[EnumMember]
Contains,
//
// 摘要:
// The string does not contain another string. Value = 50.
[EnumMember]
DoesNotContain,
//
// 摘要:
// The value is equal to the language for the user. Value = 51.
[EnumMember]
EqualUserLanguage,
//
// 摘要:
// For internal use only.
[EnumMember]
NotOn,
//
// 摘要:
// The value is older than the specified number of months. Value = 53.
[EnumMember]
OlderThanXMonths,
//
// 摘要:
// The string occurs at the beginning of another string. Value = 54.
[EnumMember]
BeginsWith,
//
// 摘要:
// The string does not begin with another string. Value = 55.
[EnumMember]
DoesNotBeginWith,
//
// 摘要:
// The string ends with another string. Value = 56.
[EnumMember]
EndsWith,
//
// 摘要:
// The string does not end with another string. Value = 57.
[EnumMember]
DoesNotEndWith,
//
// 摘要:
// The value is within the current fiscal year . Value = 58.
[EnumMember]
ThisFiscalYear,
//
// 摘要:
// The value is within the current fiscal period. Value = 59.
[EnumMember]
ThisFiscalPeriod,
//
// 摘要:
// The value is within the next fiscal year. Value = 60.
[EnumMember]
NextFiscalYear,
//
// 摘要:
// The value is within the next fiscal period. Value = 61.
[EnumMember]
NextFiscalPeriod,
//
// 摘要:
// The value is within the last fiscal year. Value = 62.
[EnumMember]
LastFiscalYear,
//
// 摘要:
// The value is within the last fiscal period. Value = 63.
[EnumMember]
LastFiscalPeriod,
//
// 摘要:
// The value is within the last X (specified value) fiscal periods. Value = 0x40.
[EnumMember]
LastXFiscalYears,
//
// 摘要:
// The value is within the last X (specified value) fiscal periods. Value = 65.
[EnumMember]
LastXFiscalPeriods,
//
// 摘要:
// The value is within the next X (specified value) fiscal years. Value = 66.
[EnumMember]
NextXFiscalYears,
//
// 摘要:
// The value is within the next X (specified value) fiscal period. Value = 67.
[EnumMember]
NextXFiscalPeriods,
//
// 摘要:
// The value is within the specified year. Value = 68.
[EnumMember]
InFiscalYear,
//
// 摘要:
// The value is within the specified fiscal period. Value = 69.
[EnumMember]
InFiscalPeriod,
//
// 摘要:
// The value is within the specified fiscal period and year. Value = 70.
[EnumMember]
InFiscalPeriodAndYear,
//
// 摘要:
// The value is within or before the specified fiscal period and year. Value = 71.
[EnumMember]
InOrBeforeFiscalPeriodAndYear,
//
// 摘要:
// The value is within or after the specified fiscal period and year. Value = 72.
[EnumMember]
InOrAfterFiscalPeriodAndYear,
//
// 摘要:
// The record is owned by teams that the user is a member of. Value = 73.
[EnumMember]
EqualUserTeams,
//
// 摘要:
// The record is owned by a user or teams that the user is a member of. Value =
// 74.
[EnumMember]
EqualUserOrUserTeams,
//
// 摘要:
// Returns all child records below the referenced record in the hierarchy. Value
// = 76.
[EnumMember]
Under,
//
// 摘要:
// Returns all records not below the referenced record in the hierarchy. Value =
// 77.
[EnumMember]
NotUnder,
//
// 摘要:
// Returns the referenced record and all child records below it in the hierarchy.
// Value = 79.
[EnumMember]
UnderOrEqual,
//
// 摘要:
// Returns all records in referenced record's hierarchical ancestry line. Value
// = 75.
[EnumMember]
Above,
//
// 摘要:
// Returns the referenced record and all records above it in the hierarchy. Value
// = 78.
[EnumMember]
AboveOrEqual,
//
// 摘要:
// When hierarchical security models are used, Equals current user or their reporting
// hierarchy. Value = 80.
[EnumMember]
EqualUserOrUserHierarchy,
//
// 摘要:
// When hierarchical security models are used, Equals current user and his teams
// or their reporting hierarchy and their teams. Value = 81.
[EnumMember]
EqualUserOrUserHierarchyAndTeams,
[EnumMember]
OlderThanXYears,
[EnumMember]
OlderThanXWeeks,
[EnumMember]
OlderThanXDays,
[EnumMember]
OlderThanXHours,
[EnumMember]
OlderThanXMinutes
}
}