440. Araxis Merge File Comparison Report

Produced by Araxis Merge on 2/1/2017 2:56:35 PM Eastern Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

440.1 Files compared

# Location File Last Modified
1 C:\Araxis_Merge_Comprasion\Pub_un\BTSSS_CIF_122016.zip\BTSSS_CIF_12_20_16\clean\CRM\trunk\SDK\SampleCode\CS\GeneralProgramming\Queries RetrieveMultipleConditionOperatorsFetch.cs Tue Dec 20 19:51:46 2016 UTC
2 Wed Feb 1 19:56:35 2017 UTC

440.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 0 0
Changed 0 0
Inserted 0 0
Removed 1 729

440.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

440.4 Active regular expressions

No regular expressions were active.

440.5 Comparison detail

1   // ======= ========== ========== ========== ========== ========== ========== ==        
2   //  This f ile is par t of the M icrosoft D ynamics CR M SDK code  samples.        
3   //        
4   //  Copyri ght (C) Mi crosoft Co rporation.   All righ ts reserve d.        
5   //        
6   //  This s ource code  is intend ed only as  a supplem ent to Mic rosoft        
7   //  Develo pment Tool s and/or o n-line doc umentation .  See the se other        
8   //  materi als for de tailed inf ormation r egarding M icrosoft c ode sample s.        
9   //        
10   //  THIS C ODE AND IN FORMATION  ARE PROVID ED "AS IS"  WITHOUT W ARRANTY OF  ANY        
11   //  KIND,  EITHER EXP RESSED OR  IMPLIED, I NCLUDING B UT NOT LIM ITED TO TH E        
12   //  IMPLIE D WARRANTI ES OF MERC HANTABILIT Y AND/OR F ITNESS FOR  A        
13   //  PARTIC ULAR PURPO SE.        
14   // ======= ========== ========== ========== ========== ========== ========== ==        
15          
16   //<snippet RetrieveMu ltipleCond itionOpera torsFetch>        
17   using Syst em;        
18   using Syst em.Linq;        
19   using Syst em.Xml.Lin q;        
20   using Syst em.Service Model;        
21   using Syst em.Collect ions.Gener ic;        
22          
23   // These n amespaces  are found  in the Mic rosoft.Xrm .Sdk.dll a ssembly        
24   // located  in the SD K\bin fold er of the  SDK downlo ad.        
25   using Micr osoft.Xrm. Sdk;        
26   using Micr osoft.Xrm. Sdk.Client ;        
27   using Micr osoft.Xrm. Sdk.Query;        
28          
29   // This na mespace is  found in  Microsoft. Crm.Sdk.Pr oxy.dll as sembly        
30   // found i n the SDK\ bin folder .        
31   using Micr osoft.Xrm. Sdk.Messag es;        
32          
33   namespace  Microsoft. Crm.Sdk.Sa mples        
34   {        
35           // / <summary >        
36           // / Demonstr ates how t o do use r etrieve mu ltiple con dition ope rators for  all        
37           // / query ty pes.</summ ary>        
38           // / <remarks >        
39           // / At run-t ime, you w ill be giv en the opt ion to del ete all th e        
40           // / database  records c reated by  this progr am.</remar ks>        
41           pu blic class  RetrieveM ultipleCon ditionOper atorsFetch        
42           {        
43                    #reg ion Class  Level Memb ers        
44          
45                    priv ate Guid _ accountId;        
46                    priv ate Guid _ productId;        
47                    priv ate Guid _ priceLevel Id;        
48                    priv ate Guid _ productPri ceId;        
49                    priv ate Guid _ unitGroupI d;        
50                    priv ate List<G uid> _cont actIdList  = new List <Guid>();        
51                    priv ate List<G uid> _oppo rtunityIdL ist = new  List<Guid> ();        
52                    priv ate List<G uid> _orde rIdList =  new List<G uid>();        
53                    priv ate Organi zationServ iceProxy _ servicePro xy;        
54           pr ivate IOrg anizationS ervice _se rvice;        
55          
56                    #end region Cla ss Level M embers        
57          
58                    #reg ion How To  Sample Co de        
59                    ///  <summary>        
60                    ///  This metho d first co nnects to  the Organi zation ser vice. Afte rwards,        
61                    ///  basic Fetc h queries  are perfor med.        
62                    ///  </summary>        
63                    ///  <param nam e="serverC onfig">Con tains serv er connect ion inform ation.</pa ram>        
64                    ///  <param nam e="promptf orDelete"> When True,  the user  will be pr ompted to  delete all        
65                    ///  created en tities.</p aram>        
66                    publ ic void Ru n(ServerCo nnection.C onfigurati on serverC onfig, boo l promptfo rDelete)        
67                    {        
68                             try        
69                             {        
70                                      //<snipp etRetrieve MultipleCo nditionOpe ratorsFetc h1>        
71                                      // Conne ct to the  Organizati on service        
72                                      // The u sing state ment assur es that th e service  proxy will  be proper ly dispose d.        
73                                      using (_ servicePro xy = new O rganizatio nServicePr oxy(server Config.Org anizationU ri, server Config.Hom eRealmUri, serverConf ig.Credent ials, serv erConfig.D eviceCrede ntials))        
74                                      {        
75                                               // This st atement is  required  to enable  early-boun d type sup port.        
76                         _servicePr oxy.Enable ProxyTypes ();        
77          
78                         _service =  (IOrganiz ationServi ce)_servic eProxy;        
79          
80                                               CreateRequ iredRecord s();        
81          
82                                               #region SQ L Query Tr anslated t o Fetch        
83                         //<snippet RetrieveMu ltipleCond itionOpera torsFetch2 >        
84                                               // Build t he followi ng SQL que ry using Q ueryExpres sion:        
85                                               //        
86                                               //               SELE CT contact .fullname,  contact.a ddress1_te lephone1        
87                                               //               FROM  contact        
88                                               //                        LEFT O UTER JOIN  account        
89                                               //                                 ON conta ct.parentc ustomerid  = account. accountid        
90                                               //                                 AND        
91                                               //                                 account. name = 'Li tware, Inc .'        
92                                               //               WHER E (contact .address1_ stateorpro vince = 'W A'        
93                                               //               AND        
94                                               //                        contac t.address1 _city in ( 'Redmond',  'Bellevue ', 'Kirkla nd', 'Seat tle')        
95                                               //               AND         
96                                               //                        contac t.address1 _telephone 1 like '(2 06)%'        
97                                               //                        OR        
98                                               //                        contac t.address1 _telephone 1 like '(4 25)%'        
99                                               //               AND        
100                                               //                        DATEDI FF(DAY, co ntact.crea tedon, GET DATE()) >  0        
101                                               //               AND        
102                                               //                        DATEDI FF(DAY, co ntact.crea tedon, GET DATE()) <  30        
103                                               //               AND        
104                                               //                        contac t.emailadd ress1 Not  NULL        
105                                               //                           )        
106          
107                                               String fet chXml = @" <fetch map ping=""log ical"" cou nt=""50""  version="" 1.0"">        
108                                                                                                   <e ntity name =""contact "">        
109                                                                                                            <att ribute nam e=""addres s1_telepho ne1"" />        
110                                                                                                            <att ribute nam e=""contac tid"" />        
111                                                                                                            <att ribute nam e=""firstn ame"" />        
112                                                                                                            <att ribute nam e=""lastna me"" />        
113                                                                                                            <fil ter>        
114                                                                                                                     <condi tion attri bute=""add ress1_stat eorprovinc e"" operat or=""eq""  value=""WA "" />        
115                                                                                                                     <condi tion attri bute=""add ress1_city "" operato r=""in"">        
116                                                                                                                              <value>R edmond</va lue>        
117                                                                                                                              <value>B ellevue</v alue>        
118                                                                                                                              <value>K irkland</v alue>        
119                                                                                                                              <value>S eattle</va lue>        
120                                                                                                                     </cond ition>        
121                                                                                                                     <condi tion attri bute=""cre atedon"" o perator="" last-x-day s"" value= ""30"" />        
122                                                                                                                     <condi tion attri bute=""ema iladdress1 "" operato r=""not-nu ll"" />        
123                                                                                                                     <filte r type=""o r"">        
124                                                                                                                              <conditi on attribu te=""addre ss1_teleph one1"" ope rator=""li ke"" value =""(206)%" " />        
125                                                                                                                              <conditi on attribu te=""addre ss1_teleph one1"" ope rator=""li ke"" value =""(425)%" " />        
126                                                                                                                     </filt er>        
127                                                                                                            </fi lter>        
128                                                                                                            <lin k-entity n ame=""acco unt"" from =""account id"" to="" parentcust omerid"">        
129                                                                                                                     <filte r>        
130                                                                                                                              <conditi on attribu te=""name" " operator =""eq"" va lue=""Litw are, Inc." " />        
131                                                                                                                     </filt er>        
132                                                                                                            </li nk-entity>        
133                                                                                                   </ entity>        
134                                                                                           </fetch>";        
135          
136                                               // Build f etch reque st and obt ain result s.        
137                         RetrieveMu ltipleRequ est efr =  new Retrie veMultiple Request()        
138                         {        
139                             Query  = new Fetc hExpressio n(fetchXml )        
140                         };        
141          
142                         EntityColl ection ent ityResults  = ((Retri eveMultipl eResponse) _service.E xecute(efr )).EntityC ollection;        
143            
144          
145                                               // Display  the resul ts.        
146                                               Console.Wr iteLine("L ist all co ntacts mat ching spec ified para meters");        
147                                               Console.Wr iteLine("= ========== ========== ========== ========== ======");        
148                         foreach (v ar e in en tityResult s.Entities )        
149                         {        
150                             Consol e.WriteLin e("Contact  ID: {0}",  e.Id);        
151                         }        
152          
153          
154                                               Console.Wr iteLine("< End of Lis ting>");        
155                         Console.Wr iteLine();        
156                         //</snippe tRetrieveM ultipleCon ditionOper atorsFetch 2>        
157                                               #endregion        
158          
159                                               #region Fi nd all ord ers fulfil led in the  last fisc al period        
160                         //<snippet RetrieveMu ltipleCond itionOpera torsFetch3 >        
161                                               fetchXml =  @"<fetch>        
162                                                                                  <entity  name='sale sorder'>        
163                                                                                           <attribute  name='nam e'/>        
164                                                                                           <filter ty pe='and'>        
165                                                                                                   <c ondition a ttribute=' datefulfil led'         
166                                                                                                            oper ator='last -fiscal-pe riod'/>        
167                                                                                           </filter>        
168                                                                                  </entity >        
169                                                                         </fetc h>";        
170          
171                                               // Build f etch reque st and obt ain result s.        
172                                               efr = new  RetrieveMu ltipleRequ est()        
173                                               {        
174                             Query  = new Fetc hExpressio n(fetchXml )        
175                                               };        
176                         entityResu lts = ((Re trieveMult ipleRespon se)_servic e.Execute( efr)).Enti tyCollecti on;        
177            
178                                               // Display  results.        
179                                               Console.Wr iteLine("L ist all or ders fulfi lled in th e last fis cal period ");        
180                                               Console.Wr iteLine("= ========== ========== ========== ========== ========== ");        
181                         foreach (v ar e in en tityResult s.Entities )        
182                         {        
183                             Consol e.WriteLin e("Fetch R etrieved:  {0}", e.At tributes[" name"]);        
184                         }        
185          
186                                               Console.Wr iteLine("< End of Lis ting>");        
187                         Console.Wr iteLine();        
188                         //</snippe tRetrieveM ultipleCon ditionOper atorsFetch 3>        
189                                               #endregion        
190          
191                                               #region Fi nd all Opp ortunities  with esti mated clos e date in  next 3 fis cal years        
192                         //<snippet RetrieveMu ltipleCond itionOpera torsFetch4 >        
193                                               fetchXml =  @"<fetch>        
194                                                                                  <entity  name='oppo rtunity'>        
195                                                                                                   <a ttribute n ame='name' />        
196                                                                                                   <f ilter type ='and'>        
197                                                                                                                     <condi tion attri bute='esti matedclose date'        
198                                                                                                                                          operato r='next-x- fiscal-yea rs'        
199                                                                                                                                          value=' 3'/>        
200                                                                                                   </ filter>        
201                                                                                  </entity >        
202                                                                         </fetc h>";        
203          
204                                               // Build f etch reque st and obt ain result s.        
205                         efr = new  RetrieveMu ltipleRequ est()        
206                         {        
207                             Query  = new Fetc hExpressio n(fetchXml )        
208                         };        
209                         entityResu lts = ((Re trieveMult ipleRespon se)_servic e.Execute( efr)).Enti tyCollecti on;        
210          
211                                                                                           // Display  results.        
212                                               Console.Wr iteLine("L ist all op portunitie s with est imated clo se date in  next 3 fi scal years ");        
213                                               Console.Wr iteLine("= ========== ========== ========== ========== ========== ========== ========== ");        
214                         foreach (v ar e in en tityResult s.Entities )        
215                         {        
216                             Consol e.WriteLin e("Fetch R etrieved:  {0}", e.At tributes[" name"]);        
217                         };        
218                                
219                                               Console.Wr iteLine("< End of Lis ting>");        
220                         Console.Wr iteLine();        
221                         //</snippe tRetrieveM ultipleCon ditionOper atorsFetch 4>        
222                                               #endregion        
223          
224                                               #region Fi nd all Ord ers fulfil led in fis cal year 2 008        
225                         //<snippet RetrieveMu ltipleCond itionOpera torsFetch5 >        
226                                               fetchXml =  @"<fetch>        
227                                                                                  <entity  name='sale sorder'>        
228                                                                                                   <a ttribute n ame='name' />        
229                                                                                                   <f ilter type ='and'>        
230                                                                                                                     <condi tion attri bute='date fulfilled'        
231                                                                                                                                          operato r='in-fisc al-year'        
232                                                                                                                                          value=' 2008'/>        
233                                                                                                   </ filter>        
234                                                                                  </entity >        
235                                                                         </fetc h>";        
236          
237                                               // Build f etch reque st and obt ain result s.        
238                         efr = new  RetrieveMu ltipleRequ est()        
239                         {        
240                             Query  = new Fetc hExpressio n(fetchXml )        
241                         };        
242                         entityResu lts = ((Re trieveMult ipleRespon se)_servic e.Execute( efr)).Enti tyCollecti on;        
243          
244                                                      
245                                               // Display  results.        
246                                               Console.Wr iteLine("L ist all or ders fulfi lled in fi scal year  2008");        
247                                               Console.Wr iteLine("= ========== ========== ========== ========== ====");        
248                         foreach (v ar e in en tityResult s.Entities )        
249                         {        
250                             Consol e.WriteLin e("Fetch R etrieved:  {0}", e.At tributes[" name"]);        
251                         }        
252                                               Console.Wr iteLine("< End of Lis ting>");        
253                         Console.Wr iteLine();        
254                         //</snippe tRetrieveM ultipleCon ditionOper atorsFetch 5>        
255                                               #endregion        
256          
257                                               #region Fi nd all Ord ers fulfil led in per iod 3 of a ny fiscal  year        
258                         //<snippet RetrieveMu ltipleCond itionOpera torsFetch6 >        
259                                               fetchXml =  @"<fetch>        
260                                                                                  <entity  name='sale sorder'>        
261                                                                                                   <a ttribute n ame='name' />        
262                                                                                                   <f ilter type ='and'>        
263                                                                                                                     <condi tion attri bute='date fulfilled'        
264                                                                                                                                          operato r='in-fisc al-period'        
265                                                                                                                                          value=' 3'/>        
266                                                                                                   </ filter>        
267                                                                                  </entity >        
268                                                                         </fetc h>";        
269          
270                                               // Build f etch reque st and obt ain result s.        
271                         efr = new  RetrieveMu ltipleRequ est()        
272                         {        
273                             Query  = new Fetc hExpressio n(fetchXml )        
274                         };        
275                         entityResu lts = ((Re trieveMult ipleRespon se)_servic e.Execute( efr)).Enti tyCollecti on;        
276          
277                                                      
278                                               // Display  results.        
279                                               Console.Wr iteLine("L ist all or ders fulfi lled in pe riod 3 of  any fiscal  year");        
280                                               Console.Wr iteLine("= ========== ========== ========== ========== ========== =====");        
281                         foreach (v ar e in en tityResult s.Entities )        
282                         {        
283                             Consol e.WriteLin e("Fetch R etrieved:  {0}", e.At tributes[" name"]);        
284                         }        
285                                               Console.Wr iteLine("< End of Lis ting>");        
286                         Console.Wr iteLine();        
287                         //</snippe tRetrieveM ultipleCon ditionOper atorsFetch 6>        
288                                               #endregion        
289          
290                                               #region Fi nd all Ord ers fulfil led in per iod 3 of f iscal year  2008        
291                         //<snippet RetrieveMu ltipleCond itionOpera torsFetch7 >        
292                                               fetchXml =  @"<fetch>        
293                                                                                  <entity  name='sale sorder'>        
294                                                                                                   <a ttribute n ame='name' />        
295                                                                                                   <f ilter type ='and'>        
296                                                                                                                     <condi tion attri bute='date fulfilled'  operator= 'in-fiscal -period-an d-year'>        
297                                                                                                                                       <value>3</ value>        
298                                                                                                                                       <value>200 8</value>        
299                                                                                                                     </cond ition>        
300                                                                                                   </ filter>        
301                                                                                  </entity >        
302                                                                         </fetc h>";        
303          
304                                               // Build f etch reque st and obt ain result s.        
305                         efr = new  RetrieveMu ltipleRequ est()        
306                         {        
307                             Query  = new Fetc hExpressio n(fetchXml )        
308                         };        
309                         entityResu lts = ((Re trieveMult ipleRespon se)_servic e.Execute( efr)).Enti tyCollecti on;        
310          
311                                                      
312                                               // Display  results.        
313                                               Console.Wr iteLine("L ist all or ders fulfi lled in pe riod 3 of  fiscal yea r 2008");        
314                                               Console.Wr iteLine("= ========== ========== ========== ========== ========== ======");        
315                         foreach (v ar e in en tityResult s.Entities )        
316                         {        
317                             Consol e.WriteLin e("Fetch R etrieved:  {0}", e.At tributes[" name"]);        
318                         }        
319                                               Console.Wr iteLine("< End of Lis ting>");        
320                         Console.Wr iteLine();        
321                         //</snippe tRetrieveM ultipleCon ditionOper atorsFetch 7>        
322                                               #endregion        
323          
324                                               // Note: t he followi ng two que ries use a ggregation  which is  only        
325                                               // possibl e to perfo rm in Fetc h, not in  QueryExpre ssion or L INQ.        
326          
327                                               #region Su m the tota l amount o f all orde rs, groupe d by year        
328                         //<snippet RetrieveMu ltipleCond itionOpera torsFetch8 >        
329                                               fetchXml =  @"<fetch  aggregate= 'true'>        
330                                                                                  <entity  name='sale sorder'>        
331                                                                                           <attribute  name='tot alamount'  aggregate= 'sum' alia s='total'/ >        
332                                                                                           <attribute  name='dat efulfilled ' groupby= 'true' dat egrouping= 'fiscal-ye ar' alias= 'datefulfi lled'/>        
333                                                                                  </entity >        
334                                                                          </fet ch>";        
335          
336                                               // Build f etch reque st and obt ain result s.        
337                         efr = new  RetrieveMu ltipleRequ est()        
338                         {        
339                             Query  = new Fetc hExpressio n(fetchXml )        
340                         };        
341                         entityResu lts = ((Re trieveMult ipleRespon se)_servic e.Execute( efr)).Enti tyCollecti on;        
342          
343                                               // Display  results.        
344                                               Console.Wr iteLine("L ist totals  of all or ders group ed by year ");        
345                                               Console.Wr iteLine("= ========== ========== ========== ========== ");        
346                         foreach (v ar e in en tityResult s.Entities )        
347                         {        
348                             Consol e.WriteLin e("Fetch R etrieved T otal: {0}" , e.Format tedValues[ "total"]);        
349                                
350                                
351                                               Console.Wr iteLine("< End of Lis ting>");        
352                         Console.Wr iteLine();        
353                         //</snippe tRetrieveM ultipleCon ditionOper atorsFetch 8>        
354                                               #endregion        
355          
356                                               #region Su m the tota l amount o f all Orde rs grouped  by period  and year        
357                         //<snippet RetrieveMu ltipleCond itionOpera torsFetch9 >        
358                                               fetchXml =  @"<fetch  aggregate= 'true'>        
359                                                                                  <entity  name='sale sorder'>        
360                                                                                           <attribute  name='tot alamount'  aggregate= 'sum' alia s='total'/ >        
361                                                                                           <attribute  name='dat efulfilled ' groupby= 'true' dat egrouping= 'fiscal-pe riod' alia s='dateful filled'/>        
362                                                                                  </entity >        
363                                                                          </fet ch>";        
364          
365                                               // Build f etch reque st and obt ain result s.        
366                         efr = new  RetrieveMu ltipleRequ est()        
367                         {        
368                             Query  = new Fetc hExpressio n(fetchXml )        
369                         };        
370                         entityResu lts = ((Re trieveMult ipleRespon se)_servic e.Execute( efr)).Enti tyCollecti on;        
371          
372                                                      
373                                               // Display  results.        
374                                               Console.Wr iteLine("L ist total  of all ord ers groupe d by perio d and year ");        
375                                               Console.Wr iteLine("= ========== ========== ========== ========== ========== ");        
376                         foreach (v ar e in en tityResult s.Entities )        
377                         {        
378                             Consol e.WriteLin e("Fetch R etrieved:  {0}", e.Fo rmattedVal ues["total "]);        
379                         }        
380                                               Console.Wr iteLine("< End of Lis ting>");        
381                         Console.Wr iteLine();        
382                         //</snippe tRetrieveM ultipleCon ditionOper atorsFetch 9>        
383                                               #endregion        
384          
385                                               DeleteRequ iredRecord s(promptfo rDelete);        
386                                      }        
387                                      //</snip petRetriev eMultipleC onditionOp eratorsFet ch1>        
388                             }        
389          
390                             // Cat ch any ser vice fault  exception s that Mic rosoft Dyn amics CRM  throws.        
391                             catch  (FaultExce ption<Micr osoft.Xrm. Sdk.Organi zationServ iceFault>)        
392                             {        
393                                      // You c an handle  an excepti on here or  pass it b ack to the  calling m ethod.        
394                                      throw;        
395                             }        
396                    }        
397          
398                    ///  <summary>        
399                    ///  Creates an y entity r ecords tha t this sam ple requir es.        
400                    ///  </summary>        
401                    publ ic void Cr eateRequir edRecords( )        
402                    {        
403                             // Cre ate a unit  group.        
404                             UoMSch edule unit Group = ne w UoMSched ule        
405                             {        
406                                      Name = " Example Un it Group",        
407                                      BaseUoMN ame = "Exa mple Prima ry Unit"        
408                             };        
409                             _unitG roupId = _ service.Cr eate(unitG roup);        
410          
411                             // Ret rieve the  unit.        
412                             QueryE xpression  unitQuery  = new Quer yExpressio n()        
413                             {        
414                                      EntityNa me = UoM.E ntityLogic alName,        
415                                      ColumnSe t = new Co lumnSet("u omid", "na me"),        
416                                      Criteria  =        
417                                      {        
418                                               Conditions  =         
419                                               {        
420                                                       ne w Conditio nExpressio n ("uomsch eduleid",  ConditionO perator.Eq ual, _unit GroupId)        
421                                               }        
422                                      },        
423                                      PageInfo  = new Pag ingInfo        
424                                      {        
425                                               PageNumber  = 1,        
426                                               Count = 1        
427                                      }        
428                             };        
429                             UoM un it = (UoM) _service.R etrieveMul tiple(unit Query).Ent ities[0];        
430          
431                             // Cre ate an acc ount.        
432                             Accoun t account  = new Acco unt        
433                             {        
434                                      Name = " Litware, I nc.",        
435                                      Address1 _StateOrPr ovince = " Colorado"        
436                             };        
437                             _accou ntId = (_s ervice.Cre ate(accoun t));        
438          
439                             // Cre ate the 2  contacts.        
440                             Contac t contact  = new Cont act()        
441                             {        
442                                      FirstNam e = "Ben",        
443                                      LastName  = "Andrew s",        
444                                      EMailAdd ress1 = "s ample@exam ple.com",        
445                                      Address1 _City = "R edmond",        
446                                      Address1 _StateOrPr ovince = " WA",        
447                                      Address1 _Telephone 1 = "(206) 555-5555",        
448                                      ParentCu stomerId =  new Entit yReference        
449                                      {        
450                                               Id = _acco untId,        
451                                               LogicalNam e = accoun t.LogicalN ame        
452                                      }        
453                             };        
454                             _conta ctIdList.A dd(_servic e.Create(c ontact));        
455          
456                             contac t = new Co ntact()        
457                             {        
458                                      FirstNam e = "Colin ",        
459                                      LastName  = "Wilcox ",        
460                                      EMailAdd ress1 = "s ample@exam ple.com",        
461                                      Address1 _City = "B ellevue",        
462                                      Address1 _StateOrPr ovince = " WA",        
463                                      Address1 _Telephone 1 = "(425) 555-5555",        
464                                      ParentCu stomerId =  new Entit yReference        
465                                      {        
466                                               Id = _acco untId,        
467                                               LogicalNam e = accoun t.LogicalN ame        
468                                      }        
469                             };        
470                             _conta ctIdList.A dd(_servic e.Create(c ontact));        
471          
472                             // Cre ate pricin g and prod uct object s.        
473                             PriceL evel price Level = ne w PriceLev el()        
474                             {        
475                                      Name = " Faux Price  List"        
476                             };        
477                             _price LevelId =  _service.C reate(pric eLevel);        
478          
479                             Produc t product  = new Prod uct()        
480                             {        
481                                      ProductN umber = "1 ",        
482                                      Quantity Decimal =  4,        
483                                      Name = " Faux Produ ct",        
484                                      Price =  new Money( 20.0M),        
485                                      DefaultU oMId = new  EntityRef erence        
486                                      {        
487                                               Id = unit. Id,        
488                                               LogicalNam e = UoM.En tityLogica lName        
489                                      },        
490                                      DefaultU oMSchedule Id = new E ntityRefer ence        
491                                      {        
492                                               Id = _unit GroupId,        
493                                               LogicalNam e = UoMSch edule.Enti tyLogicalN ame        
494                                      }        
495                             };        
496                             _produ ctId = _se rvice.Crea te(product );        
497          
498                             Produc tPriceLeve l productP rice = new  ProductPr iceLevel()        
499                             {        
500                                      PriceLev elId = new  EntityRef erence()        
501                                      {        
502                                               Id = _pric eLevelId,        
503                                               LogicalNam e = PriceL evel.Entit yLogicalNa me        
504                                      },        
505                                      ProductI d = new En tityRefere nce()        
506                                      {        
507                                               Id = _prod uctId,        
508                                               LogicalNam e = Produc t.EntityLo gicalName        
509                                      },        
510                                      UoMId =  new Entity Reference        
511                                      {        
512                                               Id = unit. Id,        
513                                               LogicalNam e = UoM.En tityLogica lName        
514                                      },        
515                                      Amount =  new Money (20.0M),        
516                             };        
517                             _produ ctPriceId  = _service .Create(pr oductPrice );        
518          
519                             // Cre ate 3 orde rs.        
520                             SalesO rder order  = new Sal esOrder()        
521                             {        
522                                      Name = " Faux Order ",        
523                                      DateFulf illed = ne w DateTime (2010, 8,  1),        
524                                      PriceLev elId = new  EntityRef erence        
525                                      {        
526                                               Id = _pric eLevelId,        
527                                               LogicalNam e = PriceL evel.Entit yLogicalNa me        
528                                      },        
529                                      Customer Id = new E ntityRefer ence        
530                                      {        
531                                               Id = _acco untId,        
532                                               LogicalNam e = accoun t.LogicalN ame        
533                                      },        
534                                      FreightA mount = ne w Money(20 .0M)        
535                             };        
536                             _order IdList.Add (_service. Create(ord er));        
537          
538                             order  = new Sale sOrder()        
539                             {        
540                                      Name = " Old Faux O rder",        
541                                      DateFulf illed = ne w DateTime (2010, 4,  1),        
542                                      PriceLev elId = new  EntityRef erence        
543                                      {        
544                                               Id = _pric eLevelId,        
545                                               LogicalNam e = PriceL evel.Entit yLogicalNa me        
546                                      },        
547                                      Customer Id = new E ntityRefer ence        
548                                      {        
549                                               Id = _acco untId,        
550                                               LogicalNam e = accoun t.LogicalN ame        
551                                      },        
552                                      FreightA mount = ne w Money(20 .0M)        
553                             };        
554                             _order IdList.Add (_service. Create(ord er));        
555          
556                             order  = new Sale sOrder()        
557                             {        
558                                      Name = " Oldest Fau x Order",        
559                                      DateFulf illed = ne w DateTime (2008, 8,  1),        
560                                      PriceLev elId = new  EntityRef erence        
561                                      {        
562                                               Id = _pric eLevelId,        
563                                               LogicalNam e = PriceL evel.Entit yLogicalNa me        
564                                      },        
565                                      Customer Id = new E ntityRefer ence        
566                                      {        
567                                               Id = _acco untId,        
568                                               LogicalNam e = accoun t.LogicalN ame        
569                                      },        
570                                      FreightA mount = ne w Money(20 .0M)        
571                             };        
572                             _order IdList.Add (_service. Create(ord er));        
573          
574                             // Cre ate 2 oppo rtunities.        
575                             Opport unity oppo rtunity =  new Opport unity()        
576                             {        
577                                      Name = " Litware, I nc. Opport unity 1",        
578                                      Estimate dCloseDate  = new Dat eTime(2011 , 1, 1),        
579                                      Customer Id = new E ntityRefer ence        
580                                      {        
581                                               Id = _acco untId,        
582                                               LogicalNam e = accoun t.LogicalN ame        
583                                      }        
584                             };        
585                             _oppor tunityIdLi st.Add(_se rvice.Crea te(opportu nity));        
586          
587                             opport unity = ne w Opportun ity()        
588                             {        
589                                      Name = " Litware, I nc. Opport unity 2",        
590                                      Estimate dCloseDate  = new Dat eTime(2020 , 1, 1),        
591                                      Customer Id = new E ntityRefer ence        
592                                      {        
593                                               Id = _acco untId,        
594                                               LogicalNam e = accoun t.LogicalN ame        
595                                      }        
596                             };        
597                             _oppor tunityIdLi st.Add(_se rvice.Crea te(opportu nity));        
598                    }        
599          
600                    ///  <summary>        
601                    ///  Deletes an y entity r ecords tha t were cre ated for t his sample .        
602                    ///  <param nam e="prompt" >Indicates  whether t o prompt t he user         
603                    ///  to delete  the record s created  in this sa mple.</par am>        
604                    ///  </summary>        
605                    publ ic void De leteRequir edRecords( bool promp t)        
606                    {        
607                             bool t oBeDeleted  = true;        
608          
609                             if (pr ompt)        
610                             {        
611                                      // Ask t he user if  the creat ed entitie s should b e deleted.        
612                                      Console. Write("\nD o you want  these ent ity record s deleted?  (y/n) [y] : ");        
613                                      String a nswer = Co nsole.Read Line();        
614                                      if (answ er.StartsW ith("y") | |        
615                                               answer.Sta rtsWith("Y ") ||        
616                                               answer ==  String.Emp ty)        
617                                      {        
618                                               toBeDelete d = true;        
619                                      }        
620                                      else        
621                                      {        
622                                               toBeDelete d = false;        
623                                      }        
624                             }        
625          
626                             if (to BeDeleted)        
627                             {        
628                                      // Delet e all reco rds create d in this  sample.        
629                                      foreach  (Guid cont actId in _ contactIdL ist)        
630                                      {        
631                                               _service.D elete(Cont act.Entity LogicalNam e, contact Id);        
632                                      }        
633          
634                                      foreach  (Guid oppo rtunityId  in _opport unityIdLis t)        
635                                      {        
636                                               _service.D elete(Oppo rtunity.En tityLogica lName, opp ortunityId );        
637                                      }        
638          
639                                      foreach  (Guid orde rId in _or derIdList)        
640                                      {        
641                                               _service.D elete(Sale sOrder.Ent ityLogical Name, orde rId);        
642                                      }        
643          
644                                      _service .Delete(Ac count.Enti tyLogicalN ame, _acco untId);        
645          
646                                      _service .Delete(Pr oduct.Enti tyLogicalN ame, _prod uctId);        
647          
648                                      _service .Delete(Pr iceLevel.E ntityLogic alName, _p riceLevelI d);        
649          
650                                      _service .Delete(Uo MSchedule. EntityLogi calName, _ unitGroupI d);        
651          
652                                      Console. WriteLine( "Entity re cord(s) ha ve been de leted.");        
653                             }        
654                    }        
655          
656                    #end region How  To Sample  Code        
657          
658                    #reg ion Main m ethod        
659          
660                    ///  <summary>        
661                    ///  Standard M ain() meth od used by  most SDK  samples.        
662                    ///  </summary>        
663                    ///  <param nam e="args">< /param>        
664                    stat ic public  void Main( string[] a rgs)        
665                    {        
666                             try        
667                             {        
668                                      // Obtai n the targ et organiz ation's We b address  and client  logon         
669                                      // crede ntials fro m the user .        
670                                      ServerCo nnection s erverConne ct = new S erverConne ction();        
671                                      ServerCo nnection.C onfigurati on config  = serverCo nnect.GetS erverConfi guration() ;        
672          
673                                      Retrieve MultipleCo nditionOpe ratorsFetc h app = ne w Retrieve MultipleCo nditionOpe ratorsFetc h();        
674                                      app.Run( config, tr ue);        
675                             }        
676                             catch  (FaultExce ption<Micr osoft.Xrm. Sdk.Organi zationServ iceFault>  ex)        
677                             {        
678                                      Console. WriteLine( "The appli cation ter minated wi th an erro r.");        
679                                      Console. WriteLine( "Timestamp : {0}", ex .Detail.Ti mestamp);        
680                                      Console. WriteLine( "Code: {0} ", ex.Deta il.ErrorCo de);        
681                                      Console. WriteLine( "Message:  {0}", ex.D etail.Mess age);        
682                                      Console. WriteLine( "Plugin Tr ace: {0}",  ex.Detail .TraceText );        
683                                      Console. WriteLine( "Inner Fau lt: {0}",        
684                                               null == ex .Detail.In nerFault ?  "No Inner  Fault" :  "Has Inner  Fault");        
685                             }        
686                             catch  (System.Ti meoutExcep tion ex)        
687                             {        
688                                      Console. WriteLine( "The appli cation ter minated wi th an erro r.");        
689                                      Console. WriteLine( "Message:  {0}", ex.M essage);        
690                                      Console. WriteLine( "Stack Tra ce: {0}",  ex.StackTr ace);        
691                                      Console. WriteLine( "Inner Fau lt: {0}",        
692                                               null == ex .InnerExce ption.Mess age ? "No  Inner Faul t" : ex.In nerExcepti on.Message );        
693                             }        
694                             catch  (System.Ex ception ex )        
695                             {        
696                                      Console. WriteLine( "The appli cation ter minated wi th an erro r.");        
697                                      Console. WriteLine( ex.Message );        
698          
699                                      // Displ ay the det ails of th e inner ex ception.        
700                                      if (ex.I nnerExcept ion != nul l)        
701                                      {        
702                                               Console.Wr iteLine(ex .InnerExce ption.Mess age);        
703          
704                                               FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n        
705                                                       as  FaultExce ption<Micr osoft.Xrm. Sdk.Organi zationServ iceFault>;        
706                                               if (fe !=  null)        
707                                               {        
708                                                       Co nsole.Writ eLine("Tim estamp: {0 }", fe.Det ail.Timest amp);        
709                                                       Co nsole.Writ eLine("Cod e: {0}", f e.Detail.E rrorCode);        
710                                                       Co nsole.Writ eLine("Mes sage: {0}" , fe.Detai l.Message) ;        
711                                                       Co nsole.Writ eLine("Plu gin Trace:  {0}", fe. Detail.Tra ceText);        
712                                                       Co nsole.Writ eLine("Inn er Fault:  {0}",        
713                                                                null  == fe.Det ail.InnerF ault ? "No  Inner Fau lt" : "Has  Inner Fau lt");        
714                                               }        
715                                      }        
716                             }        
717                             // Add itional ex ceptions t o catch: S ecurityTok enValidati onExceptio n, Expired SecurityTo kenExcepti on,        
718                             // Sec urityAcces sDeniedExc eption, Me ssageSecur ityExcepti on, and Se curityNego tiationExc eption.        
719          
720                             finall y        
721                             {        
722                                      Console. WriteLine( "Press <En ter> to ex it.");        
723                                      Console. ReadLine() ;        
724                             }        
725                    }        
726                    #end region Mai n method        
727           }        
728   }        
729   //</snippe tRetrieveM ultipleCon ditionOper atorsFetch >