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.
| # | 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 | UseLinqWithLateBinding.cs | Tue Dec 20 19:51:46 2016 UTC |
| 2 | Wed Feb 1 19:56:35 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 514 |
| 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 |
No regular expressions were active.
| 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 UseLinqWit hDotNetDat aServicesD E> | |||||
| 17 | using Syst em; | |||||
| 18 | using Syst em.Collect ions.Gener ic; | |||||
| 19 | using Syst em.Linq; | |||||
| 20 | using Syst em.Service Model; | |||||
| 21 | ||||||
| 22 | // These n amespaces are found in the Mic rosoft.Xrm .Sdk.dll a ssembly | |||||
| 23 | // located in the SD K\bin fold er of the SDK downlo ad. | |||||
| 24 | using Micr osoft.Xrm. Sdk; | |||||
| 25 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 26 | ||||||
| 27 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 28 | { | |||||
| 29 | /// <summ ary> | |||||
| 30 | /// Demon strates ho w to make LINQ queri es with th e Organiza tionServic eContext | |||||
| 31 | /// objec t and the dynamic en tity type. </summary> | |||||
| 32 | /// <rema rks> | |||||
| 33 | /// At ru n-time, yo u will be given the option to delete all the | |||||
| 34 | /// datab ase record s created by this pr ogram.</re marks> | |||||
| 35 | public cl ass UseLin qWithDotNe tDataServi cesDE | |||||
| 36 | { | |||||
| 37 | #region Class Leve l Members | |||||
| 38 | /// <sum mary> | |||||
| 39 | /// Stor es the org anization service pr oxy. | |||||
| 40 | /// </su mmary> | |||||
| 41 | private Organizati onServiceP roxy _serv iceProxy; | |||||
| 42 | // Defin e the IDs needed for this samp le. | |||||
| 43 | private List<Guid> _accountI ds = new L ist<Guid>( ); | |||||
| 44 | private List<Guid> _contactI ds = new L ist<Guid>( ); | |||||
| 45 | private List<Guid> _leadIds = new List <Guid>(); | |||||
| 46 | ||||||
| 47 | #endregi on Class L evel Membe rs | |||||
| 48 | ||||||
| 49 | #region How To Sam ple Code | |||||
| 50 | /// <sum mary> | |||||
| 51 | /// This method fi rst connec ts to the Organizati on service and servi ce context . | |||||
| 52 | /// Afte rwards, se veral LINQ query tec hniques ar e demonstr ated. | |||||
| 53 | /// </su mmary> | |||||
| 54 | /// <par am name="s erverConfi g">Contain s server c onnection informatio n.</param> | |||||
| 55 | /// <par am name="p romptforDe lete">When True, the user will be prompt ed to dele te all | |||||
| 56 | /// crea ted entiti es.</param > | |||||
| 57 | public v oid Run(Se rverConnec tion.Confi guration s erverConfi g, bool pr omptforDel ete) | |||||
| 58 | { | |||||
| 59 | try | |||||
| 60 | { | |||||
| 61 | //<sni ppetUseLin qWithDotNe tDataServi cesDE1> | |||||
| 62 | // Con nect to th e Organiza tion servi ce. | |||||
| 63 | // The using sta tement ass ures that the servic e proxy wi ll be prop erly dispo sed. | |||||
| 64 | using (_serviceP roxy = new Organizat ionService Proxy(serv erConfig.O rganizatio nUri, serv erConfig.H omeRealmUr i,serverCo nfig.Crede ntials, se rverConfig .DeviceCre dentials)) | |||||
| 65 | { | |||||
| 66 | // Th is stateme nt is requ ired to en able early -bound typ e support. | |||||
| 67 | _serv iceProxy.E nableProxy Types(); | |||||
| 68 | ||||||
| 69 | Creat eRequiredR ecords(); | |||||
| 70 | ||||||
| 71 | Organ izationSer viceContex t orgConte xt = | |||||
| 72 | n ew Organiz ationServi ceContext( _servicePr oxy); | |||||
| 73 | ||||||
| 74 | // Re trieve rec ords with Skip/Take record pag ing. Setti ng a page size | |||||
| 75 | // ca n help you manage yo ur Skip an d Take cal ls, since Skip must be | |||||
| 76 | // pa ssed a mul tiple of T ake's para meter valu e. | |||||
| 77 | //<sn ippetUseLi nqWithDotN etDataServ icesDE2> | |||||
| 78 | int p ageSize = 5; | |||||
| 79 | ||||||
| 80 | var a ccountsByP age = from a in orgC ontext.Cre ateQuery(" account") | |||||
| 81 | sele ct a["name "]; | |||||
| 82 | Syste m.Console. WriteLine( "Skip 10 a ccounts, t hen Take 5 accounts" ); | |||||
| 83 | Syste m.Console. WriteLine( "========= ========== ========== =========" ); | |||||
| 84 | forea ch (var na me in acco untsByPage .Skip(2 * pageSize). Take(pageS ize)) | |||||
| 85 | { | |||||
| 86 | Syst em.Console .WriteLine (name); | |||||
| 87 | } | |||||
| 88 | //</s nippetUseL inqWithDot NetDataSer vicesDE2> | |||||
| 89 | Syste m.Console. WriteLine( ); | |||||
| 90 | Syste m.Console. WriteLine( "<End of L isting>"); | |||||
| 91 | Syste m.Console. WriteLine( ); | |||||
| 92 | //OUT PUT: | |||||
| 93 | //Ski p 10 accou nts, then Take 5 acc ounts | |||||
| 94 | //=== ========== ========== ========== ===== | |||||
| 95 | //Fou rth Coffee 6 | |||||
| 96 | //Fou rth Coffee 7 | |||||
| 97 | //Fou rth Coffee 8 | |||||
| 98 | //Fou rth Coffee 9 | |||||
| 99 | //Fou rth Coffee 10 | |||||
| 100 | ||||||
| 101 | //<En d of Listi ng> | |||||
| 102 | ||||||
| 103 | // Us e orderBy to order i tems retri eved. | |||||
| 104 | //<sn ippetUseLi nqWithDotN etDataServ icesDE3> | |||||
| 105 | var o rderedAcco unts = fro m a in org Context.Cr eateQuery( "account") | |||||
| 106 | ord erby a["na me"] | |||||
| 107 | sel ect a["nam e"]; | |||||
| 108 | Syste m.Console. WriteLine( "Display a ccounts or dered by n ame"); | |||||
| 109 | Syste m.Console. WriteLine( "========= ========== ========== ==="); | |||||
| 110 | forea ch (var na me in orde redAccount s) | |||||
| 111 | { | |||||
| 112 | Syst em.Console .WriteLine (name); | |||||
| 113 | } | |||||
| 114 | //</s nippetUseL inqWithDot NetDataSer vicesDE3> | |||||
| 115 | Syste m.Console. WriteLine( ); | |||||
| 116 | Syste m.Console. WriteLine( "<End of L isting>"); | |||||
| 117 | Syste m.Console. WriteLine( ); | |||||
| 118 | //OUT PUT: | |||||
| 119 | //Dis play accou nts ordere d by name | |||||
| 120 | //=== ========== ========== ========= | |||||
| 121 | //A. Datum Corp oration | |||||
| 122 | //Adv enture Wor ks | |||||
| 123 | //Coh o Vineyard | |||||
| 124 | //Fab rikam | |||||
| 125 | //Fou rth Coffee 1 | |||||
| 126 | //Fou rth Coffee 10 | |||||
| 127 | //Fou rth Coffee 2 | |||||
| 128 | //Fou rth Coffee 3 | |||||
| 129 | //Fou rth Coffee 4 | |||||
| 130 | //Fou rth Coffee 5 | |||||
| 131 | //Fou rth Coffee 6 | |||||
| 132 | //Fou rth Coffee 7 | |||||
| 133 | //Fou rth Coffee 8 | |||||
| 134 | //Fou rth Coffee 9 | |||||
| 135 | //Hum ongous Ins urance | |||||
| 136 | ||||||
| 137 | //<En d of Listi ng> | |||||
| 138 | ||||||
| 139 | ||||||
| 140 | // Fi lter multi ple entiti es using L INQ. | |||||
| 141 | //<sn ippetUseLi nqWithDotN etDataServ icesDE4> | |||||
| 142 | var q uery = fro m c in org Context.Cr eateQuery( "contact") | |||||
| 143 | joi n a in org Context.Cr eateQuery( "account") | |||||
| 144 | on c["con tactid"] e quals a["p rimarycont actid"] | |||||
| 145 | whe re (String )c["lastna me"] == "W ilcox" || | |||||
| 146 | (String)c ["lastname "] == "And rews" | |||||
| 147 | whe re ((Strin g)a["addre ss1_teleph one1"]).Co ntains("(2 06)") | |||||
| 148 | || ((Stri ng)a["addr ess1_telep hone1"]).C ontains("( 425)") | |||||
| 149 | sel ect new | |||||
| 150 | { | |||||
| 151 | Co ntact = ne w | |||||
| 152 | { | |||||
| 153 | F irstName = c["firstn ame"], | |||||
| 154 | L astName = c["lastnam e"] | |||||
| 155 | }, | |||||
| 156 | Ac count = ne w | |||||
| 157 | { | |||||
| 158 | A ddress1_Te lephone1 = a["addres s1_telepho ne1"] | |||||
| 159 | } | |||||
| 160 | }; | |||||
| 161 | ||||||
| 162 | Conso le.WriteLi ne("Join a ccount and contact") ; | |||||
| 163 | Conso le.WriteLi ne("List a ll records matching specified parameters "); | |||||
| 164 | Conso le.WriteLi ne("Contac t name: Wi lcox or An drews"); | |||||
| 165 | Conso le.WriteLi ne("Accoun t area cod e: 206 or 425"); | |||||
| 166 | Conso le.WriteLi ne("====== ========== ========== ========== ========== "); | |||||
| 167 | forea ch (var re cord in qu ery) | |||||
| 168 | { | |||||
| 169 | Cons ole.WriteL ine("Conta ct Name: { 0} {1}", | |||||
| 170 | record.Con tact.First Name, reco rd.Contact .LastName) ; | |||||
| 171 | Cons ole.WriteL ine("Accou nt Phone: {0}", | |||||
| 172 | record.Acc ount.Addre ss1_Teleph one1); | |||||
| 173 | } | |||||
| 174 | //</s nippetUseL inqWithDot NetDataSer vicesDE4> | |||||
| 175 | Conso le.WriteLi ne("<End o f Listing> "); | |||||
| 176 | Conso le.WriteLi ne(); | |||||
| 177 | //OUT PUT: | |||||
| 178 | //Joi n account and contac t | |||||
| 179 | //Lis t all reco rds matchi ng specifi ed paramet ers | |||||
| 180 | //Con tact name: Wilcox or Andrews | |||||
| 181 | //Acc ount area code: 206 or 425 | |||||
| 182 | //=== ========== ========== ========== ========== === | |||||
| 183 | //Con tact Name: Ben Andre ws | |||||
| 184 | //Acc ount Phone : (206)555 -5555 | |||||
| 185 | //Con tact Name: Ben Andre ws | |||||
| 186 | //Acc ount Phone : (425)555 -5555 | |||||
| 187 | //Con tact Name: Colin Wil cox | |||||
| 188 | //Acc ount Phone : (425)555 -5555 | |||||
| 189 | //<En d of Listi ng> | |||||
| 190 | ||||||
| 191 | // Bu ild a comp lex query with LINQ. This quer y includes multiple | |||||
| 192 | // JO INs and a complex WH ERE statem ent. | |||||
| 193 | //<sn ippetUseLi nqWithDotN etDataServ icesDE5> | |||||
| 194 | var c omplexQuer y = from c in orgCon text.Creat eQuery("co ntact") | |||||
| 195 | join a in orgCon text.Creat eQuery("ac count") | |||||
| 196 | o n c["conta ctid"] equ als a["pri marycontac tid"] | |||||
| 197 | join l in orgCon text.Creat eQuery("le ad") | |||||
| 198 | o n a["origi natinglead id"] equal s l["leadi d"] | |||||
| 199 | where (String)c[ "lastname" ] == "Wilc ox" || | |||||
| 200 | ( String)c[" lastname"] == "Andre ws" | |||||
| 201 | where ((String)a ["address1 _telephone 1"]).Conta ins("(206) ") | |||||
| 202 | || ((String) a["address 1_telephon e1"]).Cont ains("(425 )") | |||||
| 203 | select new | |||||
| 204 | { | |||||
| 205 | Conta ct = new | |||||
| 206 | { | |||||
| 207 | Firs tName = c[ "firstname "], | |||||
| 208 | Last Name = c[" lastname"] | |||||
| 209 | }, | |||||
| 210 | Accou nt = new | |||||
| 211 | { | |||||
| 212 | Addr ess1_Telep hone1 = a[ "address1_ telephone1 "] | |||||
| 213 | }, | |||||
| 214 | Lead = new | |||||
| 215 | { | |||||
| 216 | Lead Id = l["le adid"] | |||||
| 217 | } | |||||
| 218 | }; | |||||
| 219 | ||||||
| 220 | Conso le.WriteLi ne("Join a ccount, co ntact and lead"); | |||||
| 221 | Conso le.WriteLi ne("List a ll records matching specified parameters "); | |||||
| 222 | Conso le.WriteLi ne("Contac t name: Wi lcox or An drews"); | |||||
| 223 | Conso le.WriteLi ne("Accoun t area cod e: 206 or 425"); | |||||
| 224 | Conso le.WriteLi ne("====== ========== ========== ========== ========== "); | |||||
| 225 | forea ch (var re cord in co mplexQuery ) | |||||
| 226 | { | |||||
| 227 | Cons ole.WriteL ine("Lead ID: {0}", | |||||
| 228 | record.Lea d.LeadId); | |||||
| 229 | Cons ole.WriteL ine("Conta ct Name: { 0} {1}", | |||||
| 230 | record.Con tact.First Name, reco rd.Contact .LastName) ; | |||||
| 231 | Cons ole.WriteL ine("Accou nt Phone: {0}", | |||||
| 232 | record.Acc ount.Addre ss1_Teleph one1); | |||||
| 233 | } | |||||
| 234 | //</s nippetUseL inqWithDot NetDataSer vicesDE5> | |||||
| 235 | Conso le.WriteLi ne("<End o f Listing> "); | |||||
| 236 | Conso le.WriteLi ne(); | |||||
| 237 | //OUT PUT: | |||||
| 238 | //Joi n account, contact a nd lead | |||||
| 239 | //Lis t all reco rds matchi ng specifi ed paramet ers | |||||
| 240 | //Con tact name: Wilcox or Andrews | |||||
| 241 | //Acc ount area code: 206 or 425 | |||||
| 242 | //=== ========== ========== ========== ========== === | |||||
| 243 | //Lea d ID: 78d5 df14-64a3- e011-aea3- 00155dba38 18 | |||||
| 244 | //Con tact Name: Colin Wil cox | |||||
| 245 | //Acc ount Phone : (425)555 -5555 | |||||
| 246 | //<En d of Listi ng> | |||||
| 247 | ||||||
| 248 | Delet eRequiredR ecords(pro mptforDele te); | |||||
| 249 | } | |||||
| 250 | //</sn ippetUseLi nqWithDotN etDataServ icesDE1> | |||||
| 251 | } | |||||
| 252 | ||||||
| 253 | // Catc h any serv ice fault exceptions that Micr osoft Dyna mics CRM t hrows. | |||||
| 254 | catch ( FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault>) | |||||
| 255 | { | |||||
| 256 | // You can handl e an excep tion here or pass it back to t he calling method. | |||||
| 257 | throw; | |||||
| 258 | } | |||||
| 259 | } | |||||
| 260 | ||||||
| 261 | /// <sum mary> | |||||
| 262 | /// Crea tes any en tity recor ds that th is sample requires. | |||||
| 263 | /// </su mmary> | |||||
| 264 | public v oid Create RequiredRe cords() | |||||
| 265 | { | |||||
| 266 | // Crea te 3 conta cts. | |||||
| 267 | Contact contact = new Conta ct() | |||||
| 268 | { | |||||
| 269 | FirstN ame = "Ben ", | |||||
| 270 | LastNa me = "Andr ews", | |||||
| 271 | EMailA ddress1 = "sample@ex ample.com" , | |||||
| 272 | Addres s1_City = "Redmond", | |||||
| 273 | Addres s1_StateOr Province = "WA" | |||||
| 274 | }; | |||||
| 275 | _contac tIds.Add(_ servicePro xy.Create( contact)); | |||||
| 276 | ||||||
| 277 | contact = new Con tact() | |||||
| 278 | { | |||||
| 279 | FirstN ame = "Col in", | |||||
| 280 | LastNa me = "Wilc ox", | |||||
| 281 | EMailA ddress1 = "sample@ex ample.com" , | |||||
| 282 | Addres s1_City = "Bellevue" , | |||||
| 283 | Addres s1_StateOr Province = "WA" | |||||
| 284 | }; | |||||
| 285 | _contac tIds.Add(_ servicePro xy.Create( contact)); | |||||
| 286 | ||||||
| 287 | contact = new Con tact() | |||||
| 288 | { | |||||
| 289 | FirstN ame = "Ben ", | |||||
| 290 | LastNa me = "Smit h", | |||||
| 291 | EMailA ddress1 = "sample@ex ample.com" , | |||||
| 292 | Addres s1_City = "Bellevue" , | |||||
| 293 | Addres s1_StateOr Province = "WA" | |||||
| 294 | }; | |||||
| 295 | _contac tIds.Add(_ servicePro xy.Create( contact)); | |||||
| 296 | ||||||
| 297 | // Crea te 3 leads . | |||||
| 298 | Lead le ad = new L ead() | |||||
| 299 | { | |||||
| 300 | FirstN ame = "Dan ", | |||||
| 301 | LastNa me = "Wils on", | |||||
| 302 | EMailA ddress1 = "sample@ex ample.com" , | |||||
| 303 | Addres s1_City = "Redmond", | |||||
| 304 | Addres s1_StateOr Province = "WA" | |||||
| 305 | }; | |||||
| 306 | _leadId s.Add(_ser viceProxy. Create(lea d)); | |||||
| 307 | ||||||
| 308 | lead = new Lead() | |||||
| 309 | { | |||||
| 310 | FirstN ame = "Jim ", | |||||
| 311 | LastNa me = "Wils on", | |||||
| 312 | EMailA ddress1 = "sample@ex ample.com" , | |||||
| 313 | Addres s1_City = "Bellevue" , | |||||
| 314 | Addres s1_StateOr Province = "WA" | |||||
| 315 | }; | |||||
| 316 | _leadId s.Add(_ser viceProxy. Create(lea d)); | |||||
| 317 | ||||||
| 318 | lead = new Lead() | |||||
| 319 | { | |||||
| 320 | FirstN ame = "Den ise", | |||||
| 321 | LastNa me = "Smit h", | |||||
| 322 | EMailA ddress1 = "sample@ex ample.com" , | |||||
| 323 | Addres s1_City = "Bellevue" , | |||||
| 324 | Addres s1_StateOr Province = "WA" | |||||
| 325 | }; | |||||
| 326 | _leadId s.Add(_ser viceProxy. Create(lea d)); | |||||
| 327 | ||||||
| 328 | // Crea te 5 custo mized Acco unts for t he LINQ sa mples. | |||||
| 329 | Account account = new Accou nt | |||||
| 330 | { | |||||
| 331 | Name = "A. Datum Corporati on", | |||||
| 332 | Addres s1_StateOr Province = "Colorado ", | |||||
| 333 | Addres s1_Telepho ne1 = "(20 6)555-5555 ", | |||||
| 334 | Primar yContactId = | |||||
| 335 | ne w EntityRe ference(Co ntact.Enti tyLogicalN ame, _cont actIds[0]) | |||||
| 336 | }; | |||||
| 337 | _accoun tIds.Add(_ servicePro xy.Create( account)); | |||||
| 338 | ||||||
| 339 | account = new Acc ount | |||||
| 340 | { | |||||
| 341 | Name = "Adventur e Works", | |||||
| 342 | Addres s1_StateOr Province = "Illinois ", | |||||
| 343 | Addres s1_County = "Lake Co unty", | |||||
| 344 | Addres s1_Telepho ne1 = "(20 6)555-5555 ", | |||||
| 345 | Origin atingLeadI d = | |||||
| 346 | ne w EntityRe ference(Le ad.EntityL ogicalName , _leadIds [0]) | |||||
| 347 | }; | |||||
| 348 | _accoun tIds.Add(_ servicePro xy.Create( account)); | |||||
| 349 | ||||||
| 350 | account = new Acc ount | |||||
| 351 | { | |||||
| 352 | Name = "Coho Vin eyard", | |||||
| 353 | Addres s1_StateOr Province = "Washingt on", | |||||
| 354 | Addres s1_County = "King Co unty", | |||||
| 355 | Addres s1_Telepho ne1 = "(42 5)555-5555 ", | |||||
| 356 | Primar yContactId = | |||||
| 357 | ne w EntityRe ference(Co ntact.Enti tyLogicalN ame, _cont actIds[1]) , | |||||
| 358 | Origin atingLeadI d = | |||||
| 359 | ne w EntityRe ference(Le ad.EntityL ogicalName , _leadIds [0]) | |||||
| 360 | }; | |||||
| 361 | _accoun tIds.Add(_ servicePro xy.Create( account)); | |||||
| 362 | ||||||
| 363 | account = new Acc ount | |||||
| 364 | { | |||||
| 365 | Name = "Fabrikam ", | |||||
| 366 | Addres s1_StateOr Province = "Washingt on", | |||||
| 367 | Addres s1_Telepho ne1 = "(42 5)555-5555 ", | |||||
| 368 | Primar yContactId = | |||||
| 369 | ne w EntityRe ference(Co ntact.Enti tyLogicalN ame, _cont actIds[0]) | |||||
| 370 | }; | |||||
| 371 | _accoun tIds.Add(_ servicePro xy.Create( account)); | |||||
| 372 | ||||||
| 373 | account = new Acc ount | |||||
| 374 | { | |||||
| 375 | Name = "Humongou s Insuranc e", | |||||
| 376 | Addres s1_StateOr Province = "Missouri ", | |||||
| 377 | Addres s1_County = "Saint L ouis Count y", | |||||
| 378 | Addres s1_Telepho ne1 = "(31 4)555-5555 ", | |||||
| 379 | Primar yContactId = | |||||
| 380 | ne w EntityRe ference(Co ntact.Enti tyLogicalN ame, _cont actIds[1]) | |||||
| 381 | }; | |||||
| 382 | _accoun tIds.Add(_ servicePro xy.Create( account)); | |||||
| 383 | ||||||
| 384 | // Crea te 10 basi c Account records. | |||||
| 385 | for (in t i = 1; i <= 10; i+ +) | |||||
| 386 | { | |||||
| 387 | accoun t = new Ac count | |||||
| 388 | { | |||||
| 389 | Name = "Fourth Coffee " + i, | |||||
| 390 | Addre ss1_StateO rProvince = "Califor nia" | |||||
| 391 | }; | |||||
| 392 | _accou ntIds.Add( _servicePr oxy.Create (account)) ; | |||||
| 393 | } | |||||
| 394 | } | |||||
| 395 | ||||||
| 396 | /// <sum mary> | |||||
| 397 | /// Dele tes any en tity recor ds that we re created for this sample. | |||||
| 398 | /// <par am name="p rompt">Ind icates whe ther to pr ompt the u ser | |||||
| 399 | /// to d elete the records cr eated in t his sample .</param> | |||||
| 400 | /// </su mmary> | |||||
| 401 | public v oid Delete RequiredRe cords(bool prompt) | |||||
| 402 | { | |||||
| 403 | bool to BeDeleted = true; | |||||
| 404 | ||||||
| 405 | if (pro mpt) | |||||
| 406 | { | |||||
| 407 | // Ask the user if the cre ated entit ies should be delete d. | |||||
| 408 | Consol e.Write("\ nDo you wa nt these e ntity reco rds delete d? (y/n) [ y]: "); | |||||
| 409 | String answer = Console.Re adLine(); | |||||
| 410 | if (an swer.Start sWith("y") || | |||||
| 411 | an swer.Start sWith("Y") || | |||||
| 412 | an swer == St ring.Empty ) | |||||
| 413 | { | |||||
| 414 | toBeD eleted = t rue; | |||||
| 415 | } | |||||
| 416 | else | |||||
| 417 | { | |||||
| 418 | toBeD eleted = f alse; | |||||
| 419 | } | |||||
| 420 | } | |||||
| 421 | ||||||
| 422 | if (toB eDeleted) | |||||
| 423 | { | |||||
| 424 | // Del ete all re cords crea ted in thi s sample. | |||||
| 425 | foreac h (Guid ac countId in _accountI ds) | |||||
| 426 | { | |||||
| 427 | _serv iceProxy.D elete(Acco unt.Entity LogicalNam e, account Id); | |||||
| 428 | } | |||||
| 429 | foreac h (Guid co ntactId in _contactI ds) | |||||
| 430 | { | |||||
| 431 | _serv iceProxy.D elete(Cont act.Entity LogicalNam e, contact Id); | |||||
| 432 | } | |||||
| 433 | foreac h (Guid le adId in _l eadIds) | |||||
| 434 | { | |||||
| 435 | _serv iceProxy.D elete(Lead .EntityLog icalName, leadId); | |||||
| 436 | } | |||||
| 437 | Consol e.WriteLin e("Entity record(s) have been deleted.") ; | |||||
| 438 | } | |||||
| 439 | } | |||||
| 440 | ||||||
| 441 | #endregi on How To Sample Cod e | |||||
| 442 | ||||||
| 443 | #region Main metho d | |||||
| 444 | ||||||
| 445 | /// <sum mary> | |||||
| 446 | /// Stan dard Main( ) method u sed by mos t SDK samp les. | |||||
| 447 | /// </su mmary> | |||||
| 448 | /// <par am name="a rgs"></par am> | |||||
| 449 | static p ublic void Main(stri ng[] args) | |||||
| 450 | { | |||||
| 451 | try | |||||
| 452 | { | |||||
| 453 | // Obt ain the ta rget organ ization's Web addres s and clie nt logon | |||||
| 454 | // cre dentials f rom the us er. | |||||
| 455 | Server Connection serverCon nect = new ServerCon nection(); | |||||
| 456 | Server Connection .Configura tion confi g = server Connect.Ge tServerCon figuration (); | |||||
| 457 | ||||||
| 458 | UseLin qWithDotNe tDataServi cesDE app = new UseL inqWithDot NetDataSer vicesDE(); | |||||
| 459 | app.Ru n(config, true); | |||||
| 460 | } | |||||
| 461 | catch ( FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> e x) | |||||
| 462 | { | |||||
| 463 | Consol e.WriteLin e("The app lication t erminated with an er ror."); | |||||
| 464 | Consol e.WriteLin e("Timesta mp: {0}", ex.Detail. Timestamp) ; | |||||
| 465 | Consol e.WriteLin e("Code: { 0}", ex.De tail.Error Code); | |||||
| 466 | Consol e.WriteLin e("Message : {0}", ex .Detail.Me ssage); | |||||
| 467 | Consol e.WriteLin e("Plugin Trace: {0} ", ex.Deta il.TraceTe xt); | |||||
| 468 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 469 | nu ll == ex.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 470 | } | |||||
| 471 | catch ( System.Tim eoutExcept ion ex) | |||||
| 472 | { | |||||
| 473 | Consol e.WriteLin e("The app lication t erminated with an er ror."); | |||||
| 474 | Consol e.WriteLin e("Message : {0}", ex .Message); | |||||
| 475 | Consol e.WriteLin e("Stack T race: {0}" , ex.Stack Trace); | |||||
| 476 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 477 | nu ll == ex.I nnerExcept ion.Messag e ? "No In ner Fault" : ex.Inne rException .Message); | |||||
| 478 | } | |||||
| 479 | catch ( System.Exc eption ex) | |||||
| 480 | { | |||||
| 481 | Consol e.WriteLin e("The app lication t erminated with an er ror."); | |||||
| 482 | Consol e.WriteLin e(ex.Messa ge); | |||||
| 483 | ||||||
| 484 | // Dis play the d etails of the inner exception. | |||||
| 485 | if (ex .InnerExce ption != n ull) | |||||
| 486 | { | |||||
| 487 | Conso le.WriteLi ne(ex.Inne rException .Message); | |||||
| 488 | ||||||
| 489 | Fault Exception< Microsoft. Xrm.Sdk.Or ganization ServiceFau lt> fe = e x.InnerExc eption | |||||
| 490 | a s FaultExc eption<Mic rosoft.Xrm .Sdk.Organ izationSer viceFault> ; | |||||
| 491 | if (f e != null) | |||||
| 492 | { | |||||
| 493 | Cons ole.WriteL ine("Times tamp: {0}" , fe.Detai l.Timestam p); | |||||
| 494 | Cons ole.WriteL ine("Code: {0}", fe. Detail.Err orCode); | |||||
| 495 | Cons ole.WriteL ine("Messa ge: {0}", fe.Detail. Message); | |||||
| 496 | Cons ole.WriteL ine("Plugi n Trace: { 0}", fe.De tail.Trace Text); | |||||
| 497 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 498 | null == fe .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 499 | } | |||||
| 500 | } | |||||
| 501 | } | |||||
| 502 | // Addi tonal exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 503 | // Secu rityAccess DeniedExce ption, Mes sageSecuri tyExceptio n, and Sec urityNegot iationExce ption. | |||||
| 504 | ||||||
| 505 | finally | |||||
| 506 | { | |||||
| 507 | Consol e.WriteLin e("Press < Enter> to exit."); | |||||
| 508 | Consol e.ReadLine (); | |||||
| 509 | } | |||||
| 510 | } | |||||
| 511 | #endregi on Main me thod | |||||
| 512 | } | |||||
| 513 | } | |||||
| 514 | //</snippe tUseLinqWi thDotNetDa taServices DE> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.