注意的是要进行CRM数据类型同.NET类型的转换
CRM Collection Linq
CRM Collection Linq
1 ColumnSet cs3 = new ColumnSet();
2 cs3.Attributes = new string[] { "name", "jade_projectdate", "createdon" };
3 QueryExpression query = new QueryExpression();
4 query.ColumnSet = cs3;
5 query.EntityName = EntityName.opportunity.ToString();
6 BusinessEntityCollection rezult = service.RetrieveMultiple(query);
7 //opportunity[] opp = (opportunity[])rezult.BusinessEntities;
8 List<opportunity> opp = new List<opportunity>();
9 foreach (BusinessEntity project in rezult.BusinessEntities)
10 {
11 opportunity temp = (opportunity)project;
12 opp.Add(temp);
13 }
14 DateTime test = (from s in opp
15 select Convert.ToDateTime(s.createdon.Value)).Max();
16 TextBox1.Text =
1 ColumnSet cs3 = new ColumnSet();
2 cs3.Attributes = new string[] { "name", "jade_projectdate", "createdon" };
3 QueryExpression query = new QueryExpression();
4 query.ColumnSet = cs3;
5 query.EntityName = EntityName.opportunity.ToString();
6 BusinessEntityCollection rezult = service.RetrieveMultiple(query);
7 //opportunity[] opp = (opportunity[])rezult.BusinessEntities;
8 List<opportunity> opp = new List<opportunity>();
9 foreach (BusinessEntity project in rezult.BusinessEntities)
10 {
11 opportunity temp = (opportunity)project;
12 opp.Add(temp);
13 }
14 DateTime test = (from s in opp
15 select Convert.ToDateTime(s.createdon.Value)).Max();
16 TextBox1.Text =
另外,还可以使用OrderExpression对Query进行GroupBy
OrderExpression
1 CrmAuthenticationToken token = new CrmAuthenticationToken();
2 token.AuthenticationType = 0;
3 token.OrganizationName = "MicrosoftCRM";
4 CrmService service = new CrmService();
5 service.Url = "http://localhost:5555/mscrmservices/2007/crmservice.asmx";
6 service.CrmAuthenticationTokenValue = token;
7 service.Credentials = System.Net.CredentialCache.DefaultCredentials;
8 ColumnSet cs = new ColumnSet();
9 cs.Attributes = new string[] { "jade_start", "jade_status", "jade_activityid" };
10 ConditionExpression conExp = new ConditionExpression();
11 conExp.Operator = ConditionOperator.EqualUserId;
12 conExp.AttributeName = "createdby";
13 FilterExpression filExp = new FilterExpression();
14 filExp.Conditions = new ConditionExpression[] { conExp };
15 OrderExpression odrExp = new OrderExpression();
16 odrExp.AttributeName = "jade_start";
17 odrExp.OrderType = OrderType.Descending;
18 OrderExpression odrExp2 = new OrderExpression();
19 odrExp2.AttributeName = "jade_pause";
20 odrExp2.OrderType = OrderType.Descending;
21 QueryExpression qryExp = new QueryExpression();
22 qryExp.ColumnSet = cs;
23 qryExp.Criteria = filExp;
24 qryExp.EntityName = "jade_timesheetdetail";
25 qryExp.Orders = new OrderExpression[] { odrExp, odrExp2 };
26 BusinessEntityCollection BEC = service.RetrieveMultiple(qryExp);
27 jade_timesheetdetail detail = (jade_timesheetdetail)BEC.BusinessEntities[0];
28 if (detail.jade_status.Value == 1)
29 TextBox1.Text = "test";
1 CrmAuthenticationToken token = new CrmAuthenticationToken();
2 token.AuthenticationType = 0;
3 token.OrganizationName = "MicrosoftCRM";
4 CrmService service = new CrmService();
5 service.Url = "http://localhost:5555/mscrmservices/2007/crmservice.asmx";
6 service.CrmAuthenticationTokenValue = token;
7 service.Credentials = System.Net.CredentialCache.DefaultCredentials;
8 ColumnSet cs = new ColumnSet();
9 cs.Attributes = new string[] { "jade_start", "jade_status", "jade_activityid" };
10 ConditionExpression conExp = new ConditionExpression();
11 conExp.Operator = ConditionOperator.EqualUserId;
12 conExp.AttributeName = "createdby";
13 FilterExpression filExp = new FilterExpression();
14 filExp.Conditions = new ConditionExpression[] { conExp };
15 OrderExpression odrExp = new OrderExpression();
16 odrExp.AttributeName = "jade_start";
17 odrExp.OrderType = OrderType.Descending;
18 OrderExpression odrExp2 = new OrderExpression();
19 odrExp2.AttributeName = "jade_pause";
20 odrExp2.OrderType = OrderType.Descending;
21 QueryExpression qryExp = new QueryExpression();
22 qryExp.ColumnSet = cs;
23 qryExp.Criteria = filExp;
24 qryExp.EntityName = "jade_timesheetdetail";
25 qryExp.Orders = new OrderExpression[] { odrExp, odrExp2 };
26 BusinessEntityCollection BEC = service.RetrieveMultiple(qryExp);
27 jade_timesheetdetail detail = (jade_timesheetdetail)BEC.BusinessEntities[0];
28 if (detail.jade_status.Value == 1)
29 TextBox1.Text = "test";