首页 > 其他分享 >Common code

Common code

时间:2023-04-14 10:44:06浏览次数:40  
标签:code name entity AddCondition Common new var query

Common code

代表段库

Csharp

查询

1.简单查询

var query = new QueryExpression("account");
var condition = new ConditionExpression("name", ConditionOperator.Equal, "Contoso");
query.Criteria.AddCondition(condition);
var order = new OrderExpression("accountnumber", OrderType.Ascending);
query.Orders.Add(order);
query.ColumnSet.AddColumns("name", "telephone1");
var results = _service.RetrieveMultiple(query);
foreach(Entity entity in results.Entities)
{
    Console.WriteLine("Name: {0}", entity.GetAttributeValue<string>("name"));
}

2.多实体联合查询(并查询)

var query = new QueryExpression("account");

var link1 = query.AddLink("contact", "primarycontactid", "contactid");
link1.LinkCriteria.AddCondition("address1_city", ConditionOperator.Equal, "Seattle");

var link2 = link1.AddLink("lead", "leadid", "originatingleadid");
link2.LinkCriteria.AddCondition("statecode", ConditionOperator.Equal, 0);

query.ColumnSet.AddColumns("name", "emailaddress1");

var results = _service.RetrieveMultiple(query);
foreach (Entity entity in results.Entities)
{
    Console.WriteLine("Name: {0}", entity.GetAttributeValue<string>("name"));
    Console.WriteLine("Email: {0}", entity.GetAttributeValue<string>("emailaddress1"));
}

3.或查询

var query = new QueryExpression("account");

var nameCondition = new ConditionExpression("name", ConditionOperator.Like, "%b%");
var cityCondition = new ConditionExpression("address1_city", ConditionOperator.Like, "%c%");
var filter = new FilterExpression(LogicalOperator.Or);
filter.AddCondition(nameCondition);
filter.AddCondition(cityCondition);

query.Criteria.AddFilter(filter);

query.ColumnSet.AddColumns("name", "address1_city", "telephone1");

var results = _service.RetrieveMultiple(query);
foreach (Entity entity in results.Entities)
{
    Console.WriteLine("Name: {0}", entity.GetAttributeValue<string>("name"));
    Console.WriteLine("City: {0}", entity.GetAttributeValue<string>("address1_city"));
    Console.WriteLine("Phone: {0}", entity.GetAttributeValue<string>("telephone1"));
}

获取用户安全角色

using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Tooling.Connector;

public static EntityCollection GetRolesForUser(IOrganizationService service, Guid systemUserId)
{
    var query = new QueryExpression("role");
    
    query.Criteria.AddCondition("businessunitid", ConditionOperator.Null);
    query.Criteria.AddCondition("ismanaged", ConditionOperator.Equal, false); //选择非管理角色

    var linkEntity = new LinkEntity("role", "systemuserroles", "roleid", "roleid", JoinOperator.Inner);
    linkEntity.LinkCriteria.AddCondition("systemuserid", ConditionOperator.Equal, systemUserId);

    query.LinkEntities.Add(linkEntity);

    var result = service.RetrieveMultiple(query);
    return result;
}

标签:code,name,entity,AddCondition,Common,new,var,query
From: https://www.cnblogs.com/gongdonghai/p/17317598.html

相关文章

  • 【前缀和】LeetCode 1031. 两个非重叠子数组的最大和
    题目链接1031.两个非重叠子数组的最大和思路代码classSolution{publicintmaxSumTwoNoOverlap(int[]nums,intfirstLen,intsecondLen){//求一个前缀和for(inti=1;i<nums.length;++i){nums[i]+=nums[i-1];}......
  • 解决 dpkg 安装出错后的 Sub-process /usr/bin/dpkg returned an error code (1) 错误
    在使用dpkg-i安装.deb软件包的过程中,会出现安装失败的可能。之后无论用sudoaptinstall-forsudaptautoremove等常见的修复命令都是无效的。网络上很多解决方案都直接给出需要运行的命令,不分析原因也不说明理由。我从来不尝试这样的解决方案,除非我自己知道或是只能死马......
  • 解决URLEncoder.encode 编码空格变 + 号
    jdk自带的URL编码工具类URLEncoder在对字符串进行URI编码的时候,会把空格编码为+号。空格的URI编码其实是:%20解决办法:对编码后的字符串,进行+号替换为%20。总感觉这种方式不优雅。使用spring提供的UriUtils来代替URLEncoder进行编码importjava.io.UnsupportedEncoding......
  • 【DP】【分治】LeetCode 53. 最大子数组和
    题目链接[https://leetcode.cn/problems/maximum-subarray/description/](53.最大子数组和"https://leetcode.cn/problems/maximum-subarray/description/")思路分析动态规划题目的时候只需要考虑最后一个阶段,因为所有的阶段转化都是相同的,考虑最后一个阶段容易发现规律在数......
  • POJ 1780 Code (欧拉回路+非递归版dfs)
    题目地址:POJ1780还是求序列的欧拉回路。只不过这题有两坑。第一坑是用数字来当点的话,会MLE,因为每个数字可以连10条边,100w条边会MLE,即使用vector也会TLE。这题可以用边来记录,对于n为1时直接输出,然后后面的,比如12,23这两个点就用边权值为123来表示这两个点,这样就把点和边的范围......
  • Codeforces Round #289 Div. 2 解题报告 A.B.C.E
    A-MaximuminTable纯递推。代码如下:#include<iostream>#include<string.h>#include<math.h>#include<queue>#include<algorithm>#include<stdlib.h>#include<map>#include<set>#include<stdio.h>usingn......
  • Codeforces Round #290 (Div. 2) 解题报告 A.B.C.D.
    A-FoxAndSnake模拟。代码如下:#include<iostream>#include<string.h>#include<math.h>#include<queue>#include<algorithm>#include<stdlib.h>#include<map>#include<set>#include<stdio.h>usingnames......
  • Codeforces Round #287 (Div. 2) 解题报告 A.B.C.D.E
    这次的CF挺水的,当时B题犯了一个很SB的错误,浪费了好多时间,所以D和E也没来得及看。sad,。。A-AmrandMusic水题,从小的开始选。代码如下:#include<iostream>#include<string.h>#include<math.h>#include<queue>#include<algorithm>#include<stdlib.h>#include<map>......
  • Codeforces Round #286 (Div. 2) C题 Mr. Kitayuta, the Treasure Hunter (DFS+记忆化D
    题目地址:http://codeforces.com/contest/505/problem/C从d点开始,每个点都有三个方向,形成了一棵树,那么就从跟结点开始进行dfs查找,dp数组记录当前的点和长度,当这两个条件相同的时候,显然,后面的子树是完全相同的,于是用记忆化来优化。代码如下:#include<iostream>#include<string.h>#......
  • codeforces #185 A Plant(矩阵快速幂+递推)
    题目地址:http://codeforces.com/problemset/problem/185/A通过这个题终于找回了点找递推公式的信心。。TAT。。不过真心感觉CF的题目质量都真不错。。。首先,第n个图形的上方,左下方,右下方的三个大三角形是跟第n-1个是一模一样的,所以是3*f(n-1)。然后只剩下中间一个倒着的大三角形了,......