0000: 2f 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a /***************
0010: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0020: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0030: 2a 2a 2a 2a 2a 2a 2a 2a 2a 0d 0a 20 2a 20 41 44 *********.. * AD
0040: 4f 2e 4e 45 54 20 32 2e 30 20 44 61 74 61 20 50 O.NET 2.0 Data P
0050: 72 6f 76 69 64 65 72 20 66 6f 72 20 53 51 4c 69 rovider for SQLi
0060: 74 65 20 56 65 72 73 69 6f 6e 20 33 2e 58 0d 0a te Version 3.X..
0070: 20 2a 20 57 72 69 74 74 65 6e 20 62 79 20 52 6f * Written by Ro
0080: 62 65 72 74 20 53 69 6d 70 73 6f 6e 20 28 72 6f bert Simpson (ro
0090: 62 65 72 74 40 62 6c 61 63 6b 63 61 73 74 6c 65 bert@blackcastle
00a0: 73 6f 66 74 2e 63 6f 6d 29 0d 0a 20 2a 0d 0a 20 soft.com).. *..
00b0: 2a 20 52 65 6c 65 61 73 65 64 20 74 6f 20 74 68 * Released to th
00c0: 65 20 70 75 62 6c 69 63 20 64 6f 6d 61 69 6e 2c e public domain,
00d0: 20 75 73 65 20 61 74 20 79 6f 75 72 20 6f 77 6e use at your own
00e0: 20 72 69 73 6b 21 0d 0a 20 2a 2a 2a 2a 2a 2a 2a risk!.. *******
00f0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0100: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0110: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0120: 2a 2f 0d 0a 0d 0a 75 73 69 6e 67 20 53 79 73 74 */....using Syst
0130: 65 6d 3b 0d 0a 75 73 69 6e 67 20 53 79 73 74 65 em;..using Syste
0140: 6d 2e 44 61 74 61 2e 43 6f 6d 6d 6f 6e 3b 0d 0a m.Data.Common;..
0150: 75 73 69 6e 67 20 53 79 73 74 65 6d 2e 44 69 61 using System.Dia
0160: 67 6e 6f 73 74 69 63 73 3b 0d 0a 75 73 69 6e 67 gnostics;..using
0170: 20 53 79 73 74 65 6d 2e 4c 69 6e 71 3b 0d 0a 75 System.Linq;..u
0180: 73 69 6e 67 20 53 79 73 74 65 6d 2e 52 65 66 6c sing System.Refl
0190: 65 63 74 69 6f 6e 3b 0d 0a 75 73 69 6e 67 20 53 ection;..using S
01a0: 79 73 74 65 6d 2e 54 65 78 74 3b 0d 0a 75 73 69 ystem.Text;..usi
01b0: 6e 67 20 53 79 73 74 65 6d 2e 54 72 61 6e 73 61 ng System.Transa
01c0: 63 74 69 6f 6e 73 3b 0d 0a 0d 0a 23 69 66 20 55 ctions;....#if U
01d0: 53 45 5f 45 4e 54 49 54 59 5f 46 52 41 4d 45 57 SE_ENTITY_FRAMEW
01e0: 4f 52 4b 5f 36 0d 0a 75 73 69 6e 67 20 53 79 73 ORK_6..using Sys
01f0: 74 65 6d 2e 44 61 74 61 2e 45 6e 74 69 74 79 2e tem.Data.Entity.
0200: 43 6f 72 65 2e 45 6e 74 69 74 79 43 6c 69 65 6e Core.EntityClien
0210: 74 3b 0d 0a 75 73 69 6e 67 20 53 79 73 74 65 6d t;..using System
0220: 2e 44 61 74 61 2e 45 6e 74 69 74 79 2e 43 6f 72 .Data.Entity.Cor
0230: 65 2e 4f 62 6a 65 63 74 73 3b 0d 0a 23 65 6c 73 e.Objects;..#els
0240: 65 0d 0a 75 73 69 6e 67 20 53 79 73 74 65 6d 2e e..using System.
0250: 44 61 74 61 2e 45 6e 74 69 74 79 43 6c 69 65 6e Data.EntityClien
0260: 74 3b 0d 0a 75 73 69 6e 67 20 53 79 73 74 65 6d t;..using System
0270: 2e 44 61 74 61 2e 4f 62 6a 65 63 74 73 3b 0d 0a .Data.Objects;..
0280: 23 65 6e 64 69 66 0d 0a 0d 0a 6e 61 6d 65 73 70 #endif....namesp
0290: 61 63 65 20 74 65 73 74 6c 69 6e 71 0d 0a 7b 0d ace testlinq..{.
02a0: 0a 20 20 63 6c 61 73 73 20 50 72 6f 67 72 61 6d . class Program
02b0: 0d 0a 20 20 7b 0d 0a 20 20 20 20 20 20 70 72 69 .. {.. pri
02c0: 76 61 74 65 20 73 74 61 74 69 63 20 69 6e 74 20 vate static int
02d0: 4d 61 69 6e 28 73 74 72 69 6e 67 5b 5d 20 61 72 Main(string[] ar
02e0: 67 73 29 0d 0a 20 20 20 20 20 20 7b 0d 0a 20 20 gs).. {..
02f0: 20 20 20 20 20 20 20 20 69 66 20 28 45 6e 76 69 if (Envi
0300: 72 6f 6e 6d 65 6e 74 2e 47 65 74 45 6e 76 69 72 ronment.GetEnvir
0310: 6f 6e 6d 65 6e 74 56 61 72 69 61 62 6c 65 28 22 onmentVariable("
0320: 42 52 45 41 4b 22 29 20 21 3d 20 6e 75 6c 6c 29 BREAK") != null)
0330: 0d 0a 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 .. {..
0340: 20 20 20 20 20 20 20 20 20 20 20 20 20 43 6f 6e Con
0350: 73 6f 6c 65 2e 57 72 69 74 65 4c 69 6e 65 28 0d sole.WriteLine(.
0360: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
0370: 20 20 20 22 41 74 74 61 63 68 20 61 20 64 65 62 "Attach a deb
0380: 75 67 67 65 72 20 74 6f 20 70 72 6f 63 65 73 73 ugger to process
0390: 20 7b 30 7d 20 61 6e 64 20 70 72 65 73 73 20 61 {0} and press a
03a0: 6e 79 20 6b 65 79 20 74 6f 20 63 6f 6e 74 69 6e ny key to contin
03b0: 75 65 2e 22 2c 0d 0a 20 20 20 20 20 20 20 20 20 ue.",..
03c0: 20 20 20 20 20 20 20 20 20 50 72 6f 63 65 73 73 Process
03d0: 2e 47 65 74 43 75 72 72 65 6e 74 50 72 6f 63 65 .GetCurrentProce
03e0: 73 73 28 29 2e 49 64 29 3b 0d 0a 0d 0a 20 20 20 ss().Id);....
03f0: 20 20 20 20 20 20 20 20 20 20 20 74 72 79 0d 0a try..
0400: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7b 0d {.
0410: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
0420: 20 20 20 43 6f 6e 73 6f 6c 65 2e 52 65 61 64 4b Console.ReadK
0430: 65 79 28 74 72 75 65 29 3b 20 2f 2a 20 74 68 72 ey(true); /* thr
0440: 6f 77 20 2a 2f 0d 0a 20 20 20 20 20 20 20 20 20 ow */..
0450: 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 }..
0460: 20 20 20 20 20 20 63 61 74 63 68 20 28 49 6e 76 catch (Inv
0470: 61 6c 69 64 4f 70 65 72 61 74 69 6f 6e 45 78 63 alidOperationExc
0480: 65 70 74 69 6f 6e 29 20 2f 2f 20 43 6f 6e 73 6f eption) // Conso
0490: 6c 65 2e 52 65 61 64 4b 65 79 0d 0a 20 20 20 20 le.ReadKey..
04a0: 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 {..
04b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
04c0: 2f 20 64 6f 20 6e 6f 74 68 69 6e 67 2e 0d 0a 20 / do nothing...
04d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a }..
04e0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
04f0: 44 65 62 75 67 67 65 72 2e 42 72 65 61 6b 28 29 Debugger.Break()
0500: 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 7d 0d 0a ;.. }..
0510: 0d 0a 20 20 20 20 20 20 20 20 20 20 73 74 72 69 .. stri
0520: 6e 67 20 61 72 67 20 3d 20 6e 75 6c 6c 3b 0d 0a ng arg = null;..
0530: 0d 0a 20 20 20 20 20 20 20 20 20 20 69 66 20 28 .. if (
0540: 28 61 72 67 73 20 21 3d 20 6e 75 6c 6c 29 20 26 (args != null) &
0550: 26 20 28 61 72 67 73 2e 4c 65 6e 67 74 68 20 3e & (args.Length >
0560: 20 30 29 29 0d 0a 20 20 20 20 20 20 20 20 20 20 0))..
0570: 20 20 20 20 61 72 67 20 3d 20 61 72 67 73 5b 30 arg = args[0
0580: 5d 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 ];....
0590: 69 66 20 28 61 72 67 20 3d 3d 20 6e 75 6c 6c 29 if (arg == null)
05a0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
05b0: 61 72 67 20 3d 20 22 22 3b 0d 0a 0d 0a 20 20 20 arg = "";....
05c0: 20 20 20 20 20 20 20 61 72 67 20 3d 20 61 72 67 arg = arg
05d0: 2e 54 72 69 6d 28 29 2e 54 72 69 6d 53 74 61 72 .Trim().TrimStar
05e0: 74 28 27 2d 27 2c 20 27 2f 27 29 2e 54 6f 4c 6f t('-', '/').ToLo
05f0: 77 65 72 49 6e 76 61 72 69 61 6e 74 28 29 3b 0d werInvariant();.
0600: 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 73 77 69 ... swi
0610: 74 63 68 20 28 61 72 67 29 0d 0a 20 20 20 20 20 tch (arg)..
0620: 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 {..
0630: 20 20 20 20 20 20 63 61 73 65 20 22 22 3a 20 2f case "": /
0640: 2f 20 53 74 72 69 6e 67 2e 45 6d 70 74 79 0d 0a / String.Empty..
0650: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 63 61 ca
0660: 73 65 20 22 6f 6c 64 22 3a 0d 0a 20 20 20 20 20 se "old":..
0670: 20 20 20 20 20 20 20 20 20 20 20 20 20 7b 0d 0a {..
0680: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0690: 20 20 20 20 20 20 72 65 74 75 72 6e 20 4f 6c 64 return Old
06a0: 54 65 73 74 73 28 29 3b 0d 0a 20 20 20 20 20 20 Tests();..
06b0: 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 }..
06c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 63 61 73 cas
06d0: 65 20 22 64 61 74 65 74 69 6d 65 22 3a 0d 0a 20 e "datetime":..
06e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
06f0: 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 {..
0700: 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e return
0710: 20 44 61 74 65 54 69 6d 65 54 65 73 74 28 29 3b DateTimeTest();
0720: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
0730: 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 20 }..
0740: 20 20 20 20 20 63 61 73 65 20 22 64 61 74 65 74 case "datet
0750: 69 6d 65 32 22 3a 0d 0a 20 20 20 20 20 20 20 20 ime2":..
0760: 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 {..
0770: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0780: 20 20 20 73 74 72 69 6e 67 20 64 61 74 65 54 69 string dateTi
0790: 6d 65 46 6f 72 6d 61 74 20 3d 20 6e 75 6c 6c 3b meFormat = null;
07a0: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 ....
07b0: 20 20 20 20 20 20 20 20 20 20 69 66 20 28 61 72 if (ar
07c0: 67 73 2e 4c 65 6e 67 74 68 20 3e 20 31 29 0d 0a gs.Length > 1)..
07d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
07e0: 20 20 20 20 20 20 20 20 20 20 64 61 74 65 54 69 dateTi
07f0: 6d 65 46 6f 72 6d 61 74 20 3d 20 61 72 67 73 5b meFormat = args[
0800: 31 5d 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 1];....
0810: 20 20 20 20 20 20 20 20 20 20 20 20 20 44 61 74 Dat
0820: 65 54 69 6d 65 54 65 73 74 32 28 64 61 74 65 54 eTimeTest2(dateT
0830: 69 6d 65 46 6f 72 6d 61 74 29 3b 0d 0a 20 20 20 imeFormat);..
0840: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0850: 20 20 20 72 65 74 75 72 6e 20 30 3b 0d 0a 20 20 return 0;..
0860: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0870: 7d 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 }..
0880: 20 63 61 73 65 20 22 73 6b 69 70 22 3a 0d 0a 20 case "skip":..
0890: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
08a0: 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 {..
08b0: 20 20 20 20 20 20 20 20 20 20 69 6e 74 20 70 61 int pa
08c0: 67 65 53 69 7a 65 20 3d 20 30 3b 0d 0a 0d 0a 20 geSize = 0;....
08d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
08e0: 20 20 20 20 20 69 66 20 28 61 72 67 73 2e 4c 65 if (args.Le
08f0: 6e 67 74 68 20 3e 20 31 29 0d 0a 20 20 20 20 20 ngth > 1)..
0900: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0910: 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 {..
0920: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 61 72 ar
0930: 67 20 3d 20 61 72 67 73 5b 31 5d 3b 0d 0a 0d 0a g = args[1];....
0940: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0950: 20 20 20 20 20 20 20 20 20 20 69 66 20 28 61 72 if (ar
0960: 67 20 21 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 20 g != null)..
0970: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0980: 20 20 20 20 20 20 20 20 20 20 70 61 67 65 53 69 pageSi
0990: 7a 65 20 3d 20 69 6e 74 2e 50 61 72 73 65 28 61 ze = int.Parse(a
09a0: 72 67 2e 54 72 69 6d 28 29 29 3b 0d 0a 20 20 20 rg.Trim());..
09b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
09c0: 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 20 20 }....
09d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 72 65 re
09e0: 74 75 72 6e 20 53 6b 69 70 54 65 73 74 28 70 61 turn SkipTest(pa
09f0: 67 65 53 69 7a 65 29 3b 0d 0a 20 20 20 20 20 20 geSize);..
0a00: 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 }..
0a10: 20 20 20 20 20 20 20 20 20 20 20 20 20 63 61 73 cas
0a20: 65 20 22 73 75 62 73 74 72 69 6e 67 22 3a 0d 0a e "substring":..
0a30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0a40: 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 {..
0a50: 20 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72 retur
0a60: 6e 20 53 75 62 53 74 72 69 6e 67 54 65 73 74 28 n SubStringTest(
0a70: 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 );..
0a80: 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 }..
0a90: 20 20 20 20 20 20 20 63 61 73 65 20 22 75 6e 69 case "uni
0aa0: 6f 6e 61 6c 6c 22 3a 0d 0a 20 20 20 20 20 20 20 onall":..
0ab0: 20 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 {..
0ac0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0ad0: 20 20 20 20 72 65 74 75 72 6e 20 55 6e 69 6f 6e return Union
0ae0: 41 6c 6c 54 65 73 74 28 29 3b 0d 0a 20 20 20 20 AllTest();..
0af0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d }.
0b00: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 63 . c
0b10: 61 73 65 20 22 65 6e 64 73 77 69 74 68 22 3a 0d ase "endswith":.
0b20: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
0b30: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 {..
0b40: 20 20 20 20 20 20 20 20 20 20 20 20 73 74 72 69 stri
0b50: 6e 67 20 76 61 6c 75 65 20 3d 20 6e 75 6c 6c 3b ng value = null;
0b60: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 ....
0b70: 20 20 20 20 20 20 20 20 20 20 69 66 20 28 61 72 if (ar
0b80: 67 73 2e 4c 65 6e 67 74 68 20 3e 20 31 29 0d 0a gs.Length > 1)..
0b90: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0ba0: 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 {..
0bb0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0bc0: 20 20 20 76 61 6c 75 65 20 3d 20 61 72 67 73 5b value = args[
0bd0: 31 5d 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 1];....
0be0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0bf0: 20 69 66 20 28 76 61 6c 75 65 20 21 3d 20 6e 75 if (value != nu
0c00: 6c 6c 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ll)..
0c10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0c20: 20 20 20 76 61 6c 75 65 20 3d 20 76 61 6c 75 65 value = value
0c30: 2e 54 72 69 6d 28 29 3b 0d 0a 20 20 20 20 20 20 .Trim();..
0c40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0c50: 7d 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 }....
0c60: 20 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72 retur
0c70: 6e 20 45 6e 64 73 57 69 74 68 54 65 73 74 28 76 n EndsWithTest(v
0c80: 61 6c 75 65 29 3b 0d 0a 20 20 20 20 20 20 20 20 alue);..
0c90: 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 }..
0ca0: 20 20 20 20 20 20 20 20 20 20 20 63 61 73 65 20 case
0cb0: 22 73 74 61 72 74 73 77 69 74 68 22 3a 0d 0a 20 "startswith":..
0cc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0cd0: 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 {..
0ce0: 20 20 20 20 20 20 20 20 20 20 73 74 72 69 6e 67 string
0cf0: 20 76 61 6c 75 65 20 3d 20 6e 75 6c 6c 3b 0d 0a value = null;..
0d00: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
0d10: 20 20 20 20 20 20 20 20 69 66 20 28 61 72 67 73 if (args
0d20: 2e 4c 65 6e 67 74 68 20 3e 20 31 29 0d 0a 20 20 .Length > 1)..
0d30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0d40: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 {..
0d50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0d60: 20 76 61 6c 75 65 20 3d 20 61 72 67 73 5b 31 5d value = args[1]
0d70: 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ;....
0d80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 i
0d90: 66 20 28 76 61 6c 75 65 20 21 3d 20 6e 75 6c 6c f (value != null
0da0: 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 )..
0db0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0dc0: 20 76 61 6c 75 65 20 3d 20 76 61 6c 75 65 2e 54 value = value.T
0dd0: 72 69 6d 28 29 3b 0d 0a 20 20 20 20 20 20 20 20 rim();..
0de0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d }.
0df0: 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ...
0e00: 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 return
0e10: 53 74 61 72 74 73 57 69 74 68 54 65 73 74 28 76 StartsWithTest(v
0e20: 61 6c 75 65 29 3b 0d 0a 20 20 20 20 20 20 20 20 alue);..
0e30: 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 }..
0e40: 20 20 20 20 20 20 20 20 20 20 20 63 61 73 65 20 case
0e50: 22 65 66 74 72 61 6e 73 61 63 74 69 6f 6e 22 3a "eftransaction":
0e60: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
0e70: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 {..
0e80: 20 20 20 20 20 20 20 20 20 20 20 20 20 62 6f 6f boo
0e90: 6c 20 76 61 6c 75 65 20 3d 20 66 61 6c 73 65 3b l value = false;
0ea0: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 ....
0eb0: 20 20 20 20 20 20 20 20 20 20 69 66 20 28 61 72 if (ar
0ec0: 67 73 2e 4c 65 6e 67 74 68 20 3e 20 31 29 0d 0a gs.Length > 1)..
0ed0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0ee0: 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 {..
0ef0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0f00: 20 20 20 69 66 20 28 21 62 6f 6f 6c 2e 54 72 79 if (!bool.Try
0f10: 50 61 72 73 65 28 61 72 67 73 5b 31 5d 2c 20 6f Parse(args[1], o
0f20: 75 74 20 76 61 6c 75 65 29 29 0d 0a 20 20 20 20 ut value))..
0f30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0f40: 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 {..
0f50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0f60: 20 20 20 20 20 20 20 43 6f 6e 73 6f 6c 65 2e 57 Console.W
0f70: 72 69 74 65 4c 69 6e 65 28 0d 0a 20 20 20 20 20 riteLine(..
0f80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0f90: 20 20 20 20 20 20 20 20 20 20 20 20 20 22 63 61 "ca
0fa0: 6e 6e 6f 74 20 70 61 72 73 65 20 5c 22 7b 30 7d nnot parse \"{0}
0fb0: 5c 22 20 61 73 20 62 6f 6f 6c 65 61 6e 22 2c 0d \" as boolean",.
0fc0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
0fd0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0fe0: 20 20 20 61 72 67 73 5b 31 5d 29 3b 0d 0a 0d 0a args[1]);....
0ff0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1000: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 72 65 re
1010: 74 75 72 6e 20 31 3b 0d 0a 20 20 20 20 20 20 20 turn 1;..
1020: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1030: 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 20 20 }..
1040: 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 0d }...
1050: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
1060: 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 45 46 return EF
1070: 54 72 61 6e 73 61 63 74 69 6f 6e 54 65 73 74 28 TransactionTest(
1080: 76 61 6c 75 65 29 3b 0d 0a 20 20 20 20 20 20 20 value);..
1090: 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 }..
10a0: 20 20 20 20 20 20 20 20 20 20 20 20 63 61 73 65 case
10b0: 20 22 69 6e 73 65 72 74 22 3a 0d 0a 20 20 20 20 "insert":..
10c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7b 0d {.
10d0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
10e0: 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 49 6e return In
10f0: 73 65 72 74 54 65 73 74 28 29 3b 0d 0a 20 20 20 sertTest();..
1100: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d }
1110: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
1120: 63 61 73 65 20 22 75 70 64 61 74 65 22 3a 0d 0a case "update":..
1130: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1140: 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 {..
1150: 20 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72 retur
1160: 6e 20 55 70 64 61 74 65 54 65 73 74 28 29 3b 0d n UpdateTest();.
1170: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
1180: 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 20 20 }..
1190: 20 20 20 20 63 61 73 65 20 22 62 69 6e 61 72 79 case "binary
11a0: 67 75 69 64 22 3a 0d 0a 20 20 20 20 20 20 20 20 guid":..
11b0: 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 {..
11c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11d0: 20 20 20 62 6f 6f 6c 20 76 61 6c 75 65 20 3d 20 bool value =
11e0: 66 61 6c 73 65 3b 0d 0a 0d 0a 20 20 20 20 20 20 false;....
11f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1200: 69 66 20 28 61 72 67 73 2e 4c 65 6e 67 74 68 20 if (args.Length
1210: 3e 20 31 29 0d 0a 20 20 20 20 20 20 20 20 20 20 > 1)..
1220: 20 20 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 {..
1230: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1240: 20 20 20 20 20 20 20 20 20 69 66 20 28 21 62 6f if (!bo
1250: 6f 6c 2e 54 72 79 50 61 72 73 65 28 61 72 67 73 ol.TryParse(args
1260: 5b 31 5d 2c 20 6f 75 74 20 76 61 6c 75 65 29 29 [1], out value))
1270: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
1280: 20 20 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 {..
1290: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
12a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 43 6f 6e Con
12b0: 73 6f 6c 65 2e 57 72 69 74 65 4c 69 6e 65 28 0d sole.WriteLine(.
12c0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
12d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
12e0: 20 20 20 22 63 61 6e 6e 6f 74 20 70 61 72 73 65 "cannot parse
12f0: 20 5c 22 7b 30 7d 5c 22 20 61 73 20 62 6f 6f 6c \"{0}\" as bool
1300: 65 61 6e 22 2c 0d 0a 20 20 20 20 20 20 20 20 20 ean",..
1310: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1320: 20 20 20 20 20 20 20 20 20 61 72 67 73 5b 31 5d args[1]
1330: 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 );....
1340: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1350: 20 20 20 20 72 65 74 75 72 6e 20 31 3b 0d 0a 20 return 1;..
1360: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1370: 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 }..
1380: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1390: 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 }....
13a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 72 65 74 ret
13b0: 75 72 6e 20 42 69 6e 61 72 79 47 75 69 64 54 65 urn BinaryGuidTe
13c0: 73 74 28 76 61 6c 75 65 29 3b 0d 0a 20 20 20 20 st(value);..
13d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d }.
13e0: 0a 23 69 66 20 4e 45 54 5f 34 30 20 7c 7c 20 4e .#if NET_40 || N
13f0: 45 54 5f 34 35 20 7c 7c 20 4e 45 54 5f 34 35 31 ET_45 || NET_451
1400: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
1410: 63 61 73 65 20 22 62 69 6e 61 72 79 67 75 69 64 case "binaryguid
1420: 32 22 3a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 2":..
1430: 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 {..
1440: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1450: 62 6f 6f 6c 20 76 61 6c 75 65 20 3d 20 66 61 6c bool value = fal
1460: 73 65 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 se;....
1470: 20 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20 if
1480: 28 61 72 67 73 2e 4c 65 6e 67 74 68 20 3e 20 31 (args.Length > 1
1490: 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 )..
14a0: 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 {..
14b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
14c0: 20 20 20 20 20 20 69 66 20 28 21 62 6f 6f 6c 2e if (!bool.
14d0: 54 72 79 50 61 72 73 65 28 61 72 67 73 5b 31 5d TryParse(args[1]
14e0: 2c 20 6f 75 74 20 76 61 6c 75 65 29 29 0d 0a 20 , out value))..
14f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1500: 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 {..
1510: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1520: 20 20 20 20 20 20 20 20 20 20 43 6f 6e 73 6f 6c Consol
1530: 65 2e 57 72 69 74 65 4c 69 6e 65 28 0d 0a 20 20 e.WriteLine(..
1540: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1550: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1560: 22 63 61 6e 6e 6f 74 20 70 61 72 73 65 20 5c 22 "cannot parse \"
1570: 7b 30 7d 5c 22 20 61 73 20 62 6f 6f 6c 65 61 6e {0}\" as boolean
1580: 22 2c 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 ",..
1590: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
15a0: 20 20 20 20 20 20 61 72 67 73 5b 31 5d 29 3b 0d args[1]);.
15b0: 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ...
15c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
15d0: 20 72 65 74 75 72 6e 20 31 3b 0d 0a 20 20 20 20 return 1;..
15e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
15f0: 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 }..
1600: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d }
1610: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 ....
1620: 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e return
1630: 20 42 69 6e 61 72 79 47 75 69 64 54 65 73 74 32 BinaryGuidTest2
1640: 28 76 61 6c 75 65 29 3b 0d 0a 20 20 20 20 20 20 (value);..
1650: 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 23 }..#
1660: 65 6e 64 69 66 0d 0a 20 20 20 20 20 20 20 20 20 endif..
1670: 20 20 20 20 20 64 65 66 61 75 6c 74 3a 0d 0a 20 default:..
1680: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1690: 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 {..
16a0: 20 20 20 20 20 20 20 20 20 20 43 6f 6e 73 6f 6c Consol
16b0: 65 2e 57 72 69 74 65 4c 69 6e 65 28 22 75 6e 6b e.WriteLine("unk
16c0: 6e 6f 77 6e 20 74 65 73 74 20 5c 22 7b 30 7d 5c nown test \"{0}\
16d0: 22 22 2c 20 61 72 67 29 3b 0d 0a 20 20 20 20 20 "", arg);..
16e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
16f0: 20 72 65 74 75 72 6e 20 31 3b 0d 0a 20 20 20 20 return 1;..
1700: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d }.
1710: 0a 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 . }..
1720: 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 2f }.... /
1730: 2f 2f 20 3c 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 // <summary>..
1740: 20 20 20 20 2f 2f 2f 20 41 74 74 65 6d 70 74 73 /// Attempts
1750: 20 74 6f 20 6f 62 74 61 69 6e 20 74 68 65 20 75 to obtain the u
1760: 6e 64 65 72 6c 79 69 6e 67 20 73 74 6f 72 65 20 nderlying store
1770: 63 6f 6e 6e 65 63 74 69 6f 6e 0d 0a 20 20 20 20 connection..
1780: 20 20 2f 2f 2f 20 28 61 20 3c 73 65 65 20 63 72 /// (a <see cr
1790: 65 66 3d 22 44 62 43 6f 6e 6e 65 63 74 69 6f 6e ef="DbConnection
17a0: 22 20 2f 3e 29 20 66 72 6f 6d 20 74 68 65 20 73 " />) from the s
17b0: 70 65 63 69 66 69 65 64 0d 0a 20 20 20 20 20 20 pecified..
17c0: 2f 2f 2f 20 3c 73 65 65 20 63 72 65 66 3d 22 45 /// <see cref="E
17d0: 6e 74 69 74 79 43 6f 6e 6e 65 63 74 69 6f 6e 22 ntityConnection"
17e0: 20 2f 3e 2e 0d 0a 20 20 20 20 20 20 2f 2f 2f 20 />... ///
17f0: 3c 2f 73 75 6d 6d 61 72 79 3e 0d 0a 20 20 20 20 </summary>..
1800: 20 20 2f 2f 2f 20 3c 70 61 72 61 6d 20 6e 61 6d /// <param nam
1810: 65 3d 22 65 6e 74 69 74 79 43 6f 6e 6e 65 63 74 e="entityConnect
1820: 69 6f 6e 22 3e 0d 0a 20 20 20 20 20 20 2f 2f 2f ion">.. ///
1830: 20 54 68 65 20 3c 73 65 65 20 63 72 65 66 3d 22 The <see cref="
1840: 45 6e 74 69 74 79 43 6f 6e 6e 65 63 74 69 6f 6e EntityConnection
1850: 22 20 2f 3e 20 74 6f 20 75 73 65 2e 0d 0a 20 20 " /> to use...
1860: 20 20 20 20 2f 2f 2f 20 3c 2f 70 61 72 61 6d 3e /// </param>
1870: 0d 0a 20 20 20 20 20 20 2f 2f 2f 20 3c 72 65 74 .. /// <ret
1880: 75 72 6e 73 3e 0d 0a 20 20 20 20 20 20 2f 2f 2f urns>.. ///
1890: 20 54 68 65 20 3c 73 65 65 20 63 72 65 66 3d 22 The <see cref="
18a0: 44 62 43 6f 6e 6e 65 63 74 69 6f 6e 22 20 2f 3e DbConnection" />
18b0: 20 2d 4f 52 2d 20 6e 75 6c 6c 20 69 66 20 69 74 -OR- null if it
18c0: 0d 0a 20 20 20 20 20 20 2f 2f 2f 20 63 61 6e 6e .. /// cann
18d0: 6f 74 20 62 65 20 64 65 74 65 72 6d 69 6e 65 64 ot be determined
18e0: 2e 0d 0a 20 20 20 20 20 20 2f 2f 2f 20 3c 2f 72 ... /// </r
18f0: 65 74 75 72 6e 73 3e 0d 0a 20 20 20 20 20 20 70 eturns>.. p
1900: 72 69 76 61 74 65 20 73 74 61 74 69 63 20 44 62 rivate static Db
1910: 43 6f 6e 6e 65 63 74 69 6f 6e 20 47 65 74 53 74 Connection GetSt
1920: 6f 72 65 43 6f 6e 6e 65 63 74 69 6f 6e 28 0d 0a oreConnection(..
1930: 20 20 20 20 20 20 20 20 20 20 45 6e 74 69 74 79 Entity
1940: 43 6f 6e 6e 65 63 74 69 6f 6e 20 65 6e 74 69 74 Connection entit
1950: 79 43 6f 6e 6e 65 63 74 69 6f 6e 0d 0a 20 20 20 yConnection..
1960: 20 20 20 20 20 20 20 29 0d 0a 20 20 20 20 20 20 )..
1970: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 2f 2f 0d {.. //.
1980: 0a 20 20 20 20 20 20 20 20 20 20 2f 2f 20 4e 4f . // NO
1990: 54 45 3a 20 4e 6f 20 65 6e 74 69 74 79 20 63 6f TE: No entity co
19a0: 6e 6e 65 63 74 69 6f 6e 2c 20 6e 6f 20 73 74 6f nnection, no sto
19b0: 72 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 2e 0d 0a re connection...
19c0: 20 20 20 20 20 20 20 20 20 20 2f 2f 0d 0a 20 20 //..
19d0: 20 20 20 20 20 20 20 20 69 66 20 28 65 6e 74 69 if (enti
19e0: 74 79 43 6f 6e 6e 65 63 74 69 6f 6e 20 3d 3d 20 tyConnection ==
19f0: 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 20 20 20 20 null)..
1a00: 20 20 20 20 20 72 65 74 75 72 6e 20 6e 75 6c 6c return null
1a10: 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 2f ;.... /
1a20: 2f 0d 0a 20 20 20 20 20 20 20 20 20 20 2f 2f 20 /.. //
1a30: 48 41 43 4b 3a 20 57 65 20 6e 65 65 64 20 74 68 HACK: We need th
1a40: 65 20 75 6e 64 65 72 6c 79 69 6e 67 20 73 74 6f e underlying sto
1a50: 72 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 61 6e re connection an
1a60: 64 0d 0a 20 20 20 20 20 20 20 20 20 20 2f 2f 20 d.. //
1a70: 20 20 20 20 20 20 74 68 65 20 6c 65 67 61 63 79 the legacy
1a80: 20 76 65 72 73 69 6f 6e 73 20 6f 66 20 74 68 65 versions of the
1a90: 20 2e 4e 45 54 20 46 72 61 6d 65 77 6f 72 6b 20 .NET Framework
1aa0: 64 6f 0d 0a 20 20 20 20 20 20 20 20 20 20 2f 2f do.. //
1ab0: 20 20 20 20 20 20 20 6e 6f 74 20 65 78 70 6f 73 not expos
1ac0: 65 20 69 74 3b 20 74 68 65 72 65 66 6f 72 65 2c e it; therefore,
1ad0: 20 61 74 74 65 6d 70 74 20 74 6f 20 67 72 61 62 attempt to grab
1ae0: 20 69 74 0d 0a 20 20 20 20 20 20 20 20 20 20 2f it.. /
1af0: 2f 20 20 20 20 20 20 20 62 79 20 66 6f 72 63 65 / by force
1b00: 2e 0d 0a 20 20 20 20 20 20 20 20 20 20 2f 2f 0d ... //.
1b10: 0a 20 20 20 20 20 20 20 20 20 20 46 69 65 6c 64 . Field
1b20: 49 6e 66 6f 20 66 69 65 6c 64 49 6e 66 6f 20 3d Info fieldInfo =
1b30: 20 74 79 70 65 6f 66 28 45 6e 74 69 74 79 43 6f typeof(EntityCo
1b40: 6e 6e 65 63 74 69 6f 6e 29 2e 47 65 74 46 69 65 nnection).GetFie
1b50: 6c 64 28 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ld(..
1b60: 20 20 20 22 5f 73 74 6f 72 65 43 6f 6e 6e 65 63 "_storeConnec
1b70: 74 69 6f 6e 22 2c 20 42 69 6e 64 69 6e 67 46 6c tion", BindingFl
1b80: 61 67 73 2e 49 6e 73 74 61 6e 63 65 20 7c 0d 0a ags.Instance |..
1b90: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 42 69 Bi
1ba0: 6e 64 69 6e 67 46 6c 61 67 73 2e 4e 6f 6e 50 75 ndingFlags.NonPu
1bb0: 62 6c 69 63 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 blic);....
1bc0: 20 20 20 20 2f 2f 0d 0a 20 20 20 20 20 20 20 20 //..
1bd0: 20 20 2f 2f 20 4e 4f 54 45 3a 20 49 66 20 74 68 // NOTE: If th
1be0: 65 20 66 69 65 6c 64 20 69 73 20 6e 6f 74 20 66 e field is not f
1bf0: 6f 75 6e 64 2c 20 6a 75 73 74 20 72 65 74 75 72 ound, just retur
1c00: 6e 20 6e 75 6c 6c 2e 0d 0a 20 20 20 20 20 20 20 n null...
1c10: 20 20 20 2f 2f 0d 0a 20 20 20 20 20 20 20 20 20 //..
1c20: 20 69 66 20 28 66 69 65 6c 64 49 6e 66 6f 20 3d if (fieldInfo =
1c30: 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 20 20 = null)..
1c40: 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 6e 75 return nu
1c50: 6c 6c 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 ll;....
1c60: 20 72 65 74 75 72 6e 20 66 69 65 6c 64 49 6e 66 return fieldInf
1c70: 6f 2e 47 65 74 56 61 6c 75 65 28 65 6e 74 69 74 o.GetValue(entit
1c80: 79 43 6f 6e 6e 65 63 74 69 6f 6e 29 20 61 73 20 yConnection) as
1c90: 44 62 43 6f 6e 6e 65 63 74 69 6f 6e 3b 0d 0a 20 DbConnection;..
1ca0: 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 }....
1cb0: 2f 2f 0d 0a 20 20 20 20 20 20 2f 2f 20 4e 4f 54 //.. // NOT
1cc0: 45 3a 20 55 73 65 64 20 74 6f 20 76 65 72 69 66 E: Used to verif
1cd0: 79 20 74 68 61 74 20 74 68 65 20 53 55 42 53 54 y that the SUBST
1ce0: 52 20 66 75 6e 63 74 69 6f 6e 20 69 73 20 75 73 R function is us
1cf0: 65 64 20 74 6f 0d 0a 20 20 20 20 20 20 2f 2f 20 ed to.. //
1d00: 20 20 20 20 20 20 69 6d 70 6c 65 6d 65 6e 74 20 implement
1d10: 74 68 65 20 53 75 62 73 74 72 69 6e 67 20 6d 65 the Substring me
1d20: 74 68 6f 64 2e 0d 0a 20 20 20 20 20 20 2f 2f 0d thod... //.
1d30: 0a 20 20 20 20 20 20 70 72 69 76 61 74 65 20 73 . private s
1d40: 74 61 74 69 63 20 69 6e 74 20 53 75 62 53 74 72 tatic int SubStr
1d50: 69 6e 67 54 65 73 74 28 29 0d 0a 20 20 20 20 20 ingTest()..
1d60: 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 75 73 {.. us
1d70: 69 6e 67 20 28 6e 6f 72 74 68 77 69 6e 64 45 46 ing (northwindEF
1d80: 45 6e 74 69 74 69 65 73 20 64 62 20 3d 20 6e 65 Entities db = ne
1d90: 77 20 6e 6f 72 74 68 77 69 6e 64 45 46 45 6e 74 w northwindEFEnt
1da0: 69 74 69 65 73 28 29 29 0d 0a 20 20 20 20 20 20 ities())..
1db0: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 {..
1dc0: 20 20 20 20 20 74 72 79 0d 0a 20 20 20 20 20 20 try..
1dd0: 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 {..
1de0: 20 20 20 20 20 20 20 20 20 20 20 20 20 62 6f 6f boo
1df0: 6c 20 6f 6e 63 65 20 3d 20 66 61 6c 73 65 3b 0d l once = false;.
1e00: 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ...
1e10: 20 20 20 20 20 76 61 72 20 71 75 65 72 79 20 3d var query =
1e20: 20 64 62 2e 43 75 73 74 6f 6d 65 72 73 2e 53 65 db.Customers.Se
1e30: 6c 65 63 74 28 0d 0a 20 20 20 20 20 20 20 20 20 lect(..
1e40: 20 20 20 20 20 20 20 20 20 20 20 20 20 70 20 3d p =
1e50: 3e 20 22 74 65 73 74 22 2e 53 75 62 73 74 72 69 > "test".Substri
1e60: 6e 67 28 31 29 20 21 3d 20 6e 75 6c 6c 29 3b 0d ng(1) != null);.
1e70: 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ...
1e80: 20 20 20 20 20 66 6f 72 65 61 63 68 20 28 76 61 foreach (va
1e90: 72 20 72 65 73 75 6c 74 20 69 6e 20 71 75 65 72 r result in quer
1ea0: 79 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 y)..
1eb0: 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 {..
1ec0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 i
1ed0: 66 20 28 6f 6e 63 65 29 0d 0a 20 20 20 20 20 20 f (once)..
1ee0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1ef0: 20 20 20 20 43 6f 6e 73 6f 6c 65 2e 57 72 69 74 Console.Writ
1f00: 65 28 27 20 27 29 3b 0d 0a 0d 0a 20 20 20 20 20 e(' ');....
1f10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f20: 20 43 6f 6e 73 6f 6c 65 2e 57 72 69 74 65 28 72 Console.Write(r
1f30: 65 73 75 6c 74 29 3b 0d 0a 0d 0a 20 20 20 20 20 esult);....
1f40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f50: 20 6f 6e 63 65 20 3d 20 74 72 75 65 3b 0d 0a 20 once = true;..
1f60: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f70: 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 }....
1f80: 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 30 return 0
1f90: 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ;..
1fa0: 20 7d 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 }..
1fb0: 20 20 63 61 74 63 68 20 28 45 78 63 65 70 74 69 catch (Excepti
1fc0: 6f 6e 20 65 29 0d 0a 20 20 20 20 20 20 20 20 20 on e)..
1fd0: 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 {..
1fe0: 20 20 20 20 20 20 20 20 20 20 43 6f 6e 73 6f 6c Consol
1ff0: 65 2e 57 72 69 74 65 4c 69 6e 65 28 65 29 3b 0d e.WriteLine(e);.
2000: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d . }
2010: 0d 0a 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 0d .. }...
2020: 0a 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72 . retur
2030: 6e 20 31 3b 0d 0a 20 20 20 20 20 20 7d 0d 0a 0d n 1;.. }...
2040: 0a 20 20 20 20 20 20 2f 2f 0d 0a 20 20 20 20 20 . //..
2050: 20 2f 2f 20 4e 4f 54 45 3a 20 55 73 65 64 20 74 // NOTE: Used t
2060: 6f 20 74 65 73 74 20 74 68 65 20 66 69 78 20 66 o test the fix f
2070: 6f 72 20 74 69 63 6b 65 74 20 5b 38 62 37 64 31 or ticket [8b7d1
2080: 37 39 63 33 63 5d 2e 0d 0a 20 20 20 20 20 20 2f 79c3c]... /
2090: 2f 0d 0a 20 20 20 20 20 20 70 72 69 76 61 74 65 /.. private
20a0: 20 73 74 61 74 69 63 20 69 6e 74 20 53 6b 69 70 static int Skip
20b0: 54 65 73 74 28 69 6e 74 20 70 61 67 65 53 69 7a Test(int pageSiz
20c0: 65 29 0d 0a 20 20 20 20 20 20 7b 0d 0a 20 20 20 e).. {..
20d0: 20 20 20 20 20 20 20 75 73 69 6e 67 20 28 6e 6f using (no
20e0: 72 74 68 77 69 6e 64 45 46 45 6e 74 69 74 69 65 rthwindEFEntitie
20f0: 73 20 64 62 20 3d 20 6e 65 77 20 6e 6f 72 74 68 s db = new north
2100: 77 69 6e 64 45 46 45 6e 74 69 74 69 65 73 28 29 windEFEntities()
2110: 29 0d 0a 20 20 20 20 20 20 20 20 20 20 7b 0d 0a ).. {..
2120: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 62 6f bo
2130: 6f 6c 20 6f 6e 63 65 20 3d 20 66 61 6c 73 65 3b ol once = false;
2140: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
2150: 69 6e 74 20 63 6f 75 6e 74 20 3d 20 64 62 2e 43 int count = db.C
2160: 75 73 74 6f 6d 65 72 73 2e 43 6f 75 6e 74 28 29 ustomers.Count()
2170: 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ;....
2180: 20 20 20 69 6e 74 20 50 61 67 65 43 6f 75 6e 74 int PageCount
2190: 20 3d 20 28 70 61 67 65 53 69 7a 65 20 21 3d 20 = (pageSize !=
21a0: 30 29 20 3f 0d 0a 20 20 20 20 20 20 20 20 20 20 0) ?..
21b0: 20 20 20 20 20 20 20 20 28 63 6f 75 6e 74 20 2f (count /
21c0: 20 70 61 67 65 53 69 7a 65 29 20 2b 20 28 28 63 pageSize) + ((c
21d0: 6f 75 6e 74 20 25 20 70 61 67 65 53 69 7a 65 29 ount % pageSize)
21e0: 20 3d 3d 20 30 20 3f 20 30 20 3a 20 31 29 20 3a == 0 ? 0 : 1) :
21f0: 20 31 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 1;....
2200: 20 20 20 20 20 66 6f 72 20 28 69 6e 74 20 70 61 for (int pa
2210: 67 65 49 6e 64 65 78 20 3d 20 30 3b 20 70 61 67 geIndex = 0; pag
2220: 65 49 6e 64 65 78 20 3c 20 50 61 67 65 43 6f 75 eIndex < PageCou
2230: 6e 74 3b 20 70 61 67 65 49 6e 64 65 78 2b 2b 29 nt; pageIndex++)
2240: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
2250: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 {..
2260: 20 20 20 20 20 76 61 72 20 71 75 65 72 79 20 3d var query =
2270: 20 64 62 2e 43 75 73 74 6f 6d 65 72 73 2e 4f 72 db.Customers.Or
2280: 64 65 72 42 79 28 70 20 3d 3e 20 70 2e 43 69 74 derBy(p => p.Cit
2290: 79 29 2e 0d 0a 20 20 20 20 20 20 20 20 20 20 20 y)...
22a0: 20 20 20 20 20 20 20 20 20 20 20 53 6b 69 70 28 Skip(
22b0: 70 61 67 65 53 69 7a 65 20 2a 20 70 61 67 65 49 pageSize * pageI
22c0: 6e 64 65 78 29 2e 54 61 6b 65 28 70 61 67 65 53 ndex).Take(pageS
22d0: 69 7a 65 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 ize);....
22e0: 20 20 20 20 20 20 20 20 20 20 20 66 6f 72 65 61 forea
22f0: 63 68 20 28 43 75 73 74 6f 6d 65 72 73 20 63 75 ch (Customers cu
2300: 73 74 6f 6d 65 72 73 20 69 6e 20 71 75 65 72 79 stomers in query
2310: 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 )..
2320: 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 {..
2330: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 66 if
2340: 20 28 6f 6e 63 65 29 0d 0a 20 20 20 20 20 20 20 (once)..
2350: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2360: 20 20 20 43 6f 6e 73 6f 6c 65 2e 57 72 69 74 65 Console.Write
2370: 28 27 20 27 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 (' ');....
2380: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2390: 43 6f 6e 73 6f 6c 65 2e 57 72 69 74 65 28 63 75 Console.Write(cu
23a0: 73 74 6f 6d 65 72 73 2e 43 75 73 74 6f 6d 65 72 stomers.Customer
23b0: 49 44 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 ID);....
23c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 6f 6e on
23d0: 63 65 20 3d 20 74 72 75 65 3b 0d 0a 20 20 20 20 ce = true;..
23e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d }.
23f0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d . }
2400: 0d 0a 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 0d .. }...
2410: 0a 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72 . retur
2420: 6e 20 30 3b 0d 0a 20 20 20 20 20 20 7d 0d 0a 0d n 0;.. }...
2430: 0a 20 20 20 20 20 20 2f 2f 0d 0a 20 20 20 20 20 . //..
2440: 20 2f 2f 20 4e 4f 54 45 3a 20 55 73 65 64 20 74 // NOTE: Used t
2450: 6f 20 74 65 73 74 20 74 68 65 20 66 69 78 20 66 o test the fix f
2460: 6f 72 20 74 69 63 6b 65 74 20 5b 35 39 65 64 63 or ticket [59edc
2470: 31 30 31 38 62 5d 2e 0d 0a 20 20 20 20 20 20 2f 1018b]... /
2480: 2f 0d 0a 20 20 20 20 20 20 70 72 69 76 61 74 65 /.. private
2490: 20 73 74 61 74 69 63 20 69 6e 74 20 45 6e 64 73 static int Ends
24a0: 57 69 74 68 54 65 73 74 28 73 74 72 69 6e 67 20 WithTest(string
24b0: 76 61 6c 75 65 29 0d 0a 20 20 20 20 20 20 7b 0d value).. {.
24c0: 0a 20 20 20 20 20 20 20 20 20 20 75 73 69 6e 67 . using
24d0: 20 28 6e 6f 72 74 68 77 69 6e 64 45 46 45 6e 74 (northwindEFEnt
24e0: 69 74 69 65 73 20 64 62 20 3d 20 6e 65 77 20 6e ities db = new n
24f0: 6f 72 74 68 77 69 6e 64 45 46 45 6e 74 69 74 69 orthwindEFEntiti
2500: 65 73 28 29 29 0d 0a 20 20 20 20 20 20 20 20 20 es())..
2510: 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 {..
2520: 20 20 62 6f 6f 6c 20 6f 6e 63 65 20 3d 20 66 61 bool once = fa
2530: 6c 73 65 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 lse;..
2540: 20 20 20 20 76 61 72 20 71 75 65 72 79 20 3d 20 var query =
2550: 66 72 6f 6d 20 63 20 69 6e 20 64 62 2e 43 75 73 from c in db.Cus
2560: 74 6f 6d 65 72 73 0d 0a 20 20 20 20 20 20 20 20 tomers..
2570: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2580: 20 20 77 68 65 72 65 20 63 2e 43 69 74 79 2e 45 where c.City.E
2590: 6e 64 73 57 69 74 68 28 76 61 6c 75 65 29 0d 0a ndsWith(value)..
25a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
25b0: 20 20 20 20 20 20 20 20 20 20 6f 72 64 65 72 62 orderb
25c0: 79 20 63 2e 43 75 73 74 6f 6d 65 72 49 44 0d 0a y c.CustomerID..
25d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
25e0: 20 20 20 20 20 20 20 20 20 20 73 65 6c 65 63 74 select
25f0: 20 63 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 c;....
2600: 20 20 20 20 20 66 6f 72 65 61 63 68 20 28 43 75 foreach (Cu
2610: 73 74 6f 6d 65 72 73 20 63 75 73 74 6f 6d 65 72 stomers customer
2620: 73 20 69 6e 20 71 75 65 72 79 29 0d 0a 20 20 20 s in query)..
2630: 20 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 {..
2640: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2650: 69 66 20 28 6f 6e 63 65 29 0d 0a 20 20 20 20 20 if (once)..
2660: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2670: 20 43 6f 6e 73 6f 6c 65 2e 57 72 69 74 65 28 27 Console.Write('
2680: 20 27 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 ');....
2690: 20 20 20 20 20 20 20 20 20 20 43 6f 6e 73 6f 6c Consol
26a0: 65 2e 57 72 69 74 65 28 63 75 73 74 6f 6d 65 72 e.Write(customer
26b0: 73 2e 43 75 73 74 6f 6d 65 72 49 44 29 3b 0d 0a s.CustomerID);..
26c0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
26d0: 20 20 20 20 6f 6e 63 65 20 3d 20 74 72 75 65 3b once = true;
26e0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
26f0: 7d 0d 0a 20 20 20 20 20 20 20 20 20 20 7d 0d 0a }.. }..
2700: 0d 0a 20 20 20 20 20 20 20 20 20 20 72 65 74 75 .. retu
2710: 72 6e 20 30 3b 0d 0a 20 20 20 20 20 20 7d 0d 0a rn 0;.. }..
2720: 0d 0a 20 20 20 20 20 20 2f 2f 0d 0a 20 20 20 20 .. //..
2730: 20 20 2f 2f 20 4e 4f 54 45 3a 20 55 73 65 64 20 // NOTE: Used
2740: 74 6f 20 76 65 72 69 66 79 20 74 68 65 20 62 65 to verify the be
2750: 68 61 76 69 6f 72 20 66 72 6f 6d 20 74 69 63 6b havior from tick
2760: 65 74 20 5b 30 30 66 38 36 66 39 37 33 39 5d 2e et [00f86f9739].
2770: 0d 0a 20 20 20 20 20 20 2f 2f 0d 0a 20 20 20 20 .. //..
2780: 20 20 70 72 69 76 61 74 65 20 73 74 61 74 69 63 private static
2790: 20 69 6e 74 20 53 74 61 72 74 73 57 69 74 68 54 int StartsWithT
27a0: 65 73 74 28 73 74 72 69 6e 67 20 76 61 6c 75 65 est(string value
27b0: 29 0d 0a 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 ).. {..
27c0: 20 20 20 20 20 20 75 73 69 6e 67 20 28 6e 6f 72 using (nor
27d0: 74 68 77 69 6e 64 45 46 45 6e 74 69 74 69 65 73 thwindEFEntities
27e0: 20 64 62 20 3d 20 6e 65 77 20 6e 6f 72 74 68 77 db = new northw
27f0: 69 6e 64 45 46 45 6e 74 69 74 69 65 73 28 29 29 indEFEntities())
2800: 0d 0a 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 .. {..
2810: 20 20 20 20 20 20 20 20 20 20 20 20 20 62 6f 6f boo
2820: 6c 20 6f 6e 63 65 20 3d 20 66 61 6c 73 65 3b 0d l once = false;.
2830: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 76 . v
2840: 61 72 20 71 75 65 72 79 20 3d 20 66 72 6f 6d 20 ar query = from
2850: 63 20 69 6e 20 64 62 2e 43 75 73 74 6f 6d 65 72 c in db.Customer
2860: 73 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 s..
2870: 20 20 20 20 20 20 20 20 20 20 20 20 20 77 68 65 whe
2880: 72 65 20 63 2e 43 69 74 79 2e 53 74 61 72 74 73 re c.City.Starts
2890: 57 69 74 68 28 76 61 6c 75 65 29 0d 0a 20 20 20 With(value)..
28a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
28b0: 20 20 20 20 20 20 20 6f 72 64 65 72 62 79 20 63 orderby c
28c0: 2e 43 75 73 74 6f 6d 65 72 49 44 0d 0a 20 20 20 .CustomerID..
28d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
28e0: 20 20 20 20 20 20 20 73 65 6c 65 63 74 20 63 3b select c;
28f0: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 ....
2900: 20 20 66 6f 72 65 61 63 68 20 28 43 75 73 74 6f foreach (Custo
2910: 6d 65 72 73 20 63 75 73 74 6f 6d 65 72 73 20 69 mers customers i
2920: 6e 20 71 75 65 72 79 29 0d 0a 20 20 20 20 20 20 n query)..
2930: 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 {..
2940: 20 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20 if
2950: 28 6f 6e 63 65 29 0d 0a 20 20 20 20 20 20 20 20 (once)..
2960: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 43 6f Co
2970: 6e 73 6f 6c 65 2e 57 72 69 74 65 28 27 20 27 29 nsole.Write(' ')
2980: 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ;....
2990: 20 20 20 20 20 20 20 43 6f 6e 73 6f 6c 65 2e 57 Console.W
29a0: 72 69 74 65 28 63 75 73 74 6f 6d 65 72 73 2e 43 rite(customers.C
29b0: 75 73 74 6f 6d 65 72 49 44 29 3b 0d 0a 0d 0a 20 ustomerID);....
29c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
29d0: 20 6f 6e 63 65 20 3d 20 74 72 75 65 3b 0d 0a 20 once = true;..
29e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a }..
29f0: 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 }....
2a00: 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 return
2a10: 30 3b 0d 0a 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 0;.. }....
2a20: 20 20 20 20 20 2f 2f 0d 0a 20 20 20 20 20 20 2f //.. /
2a30: 2f 20 4e 4f 54 45 3a 20 55 73 65 64 20 74 6f 20 / NOTE: Used to
2a40: 74 65 73 74 20 74 68 65 20 66 69 78 20 66 6f 72 test the fix for
2a50: 20 74 69 63 6b 65 74 20 5b 30 61 33 32 38 38 35 ticket [0a32885
2a60: 31 30 39 5d 2e 0d 0a 20 20 20 20 20 20 2f 2f 0d 109]... //.
2a70: 0a 20 20 20 20 20 20 70 72 69 76 61 74 65 20 73 . private s
2a80: 74 61 74 69 63 20 69 6e 74 20 55 6e 69 6f 6e 41 tatic int UnionA
2a90: 6c 6c 54 65 73 74 28 29 0d 0a 20 20 20 20 20 20 llTest()..
2aa0: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 75 73 69 {.. usi
2ab0: 6e 67 20 28 6e 6f 72 74 68 77 69 6e 64 45 46 45 ng (northwindEFE
2ac0: 6e 74 69 74 69 65 73 20 64 62 20 3d 20 6e 65 77 ntities db = new
2ad0: 20 6e 6f 72 74 68 77 69 6e 64 45 46 45 6e 74 69 northwindEFEnti
2ae0: 74 69 65 73 28 29 29 0d 0a 20 20 20 20 20 20 20 ties())..
2af0: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 {..
2b00: 20 20 20 20 62 6f 6f 6c 20 6f 6e 63 65 20 3d 20 bool once =
2b10: 66 61 6c 73 65 3b 0d 0a 0d 0a 20 20 20 20 20 20 false;....
2b20: 20 20 20 20 20 20 20 20 76 61 72 20 63 75 73 74 var cust
2b30: 6f 6d 65 72 73 31 20 3d 20 64 62 2e 43 75 73 74 omers1 = db.Cust
2b40: 6f 6d 65 72 73 2e 57 68 65 72 65 28 0d 0a 20 20 omers.Where(..
2b50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2b60: 66 20 3d 3e 20 66 2e 4f 72 64 65 72 73 2e 41 6e f => f.Orders.An
2b70: 79 28 29 29 2e 4f 72 64 65 72 42 79 44 65 73 63 y()).OrderByDesc
2b80: 65 6e 64 69 6e 67 28 0d 0a 20 20 20 20 20 20 20 ending(..
2b90: 20 20 20 20 20 20 20 20 20 20 20 20 20 66 20 3d f =
2ba0: 3e 20 66 2e 43 6f 6d 70 61 6e 79 4e 61 6d 65 29 > f.CompanyName)
2bb0: 2e 53 6b 69 70 28 31 29 2e 54 61 6b 65 28 31 29 .Skip(1).Take(1)
2bc0: 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ;....
2bd0: 20 20 20 76 61 72 20 63 75 73 74 6f 6d 65 72 73 var customers
2be0: 32 20 3d 20 64 62 2e 43 75 73 74 6f 6d 65 72 73 2 = db.Customers
2bf0: 2e 57 68 65 72 65 28 0d 0a 20 20 20 20 20 20 20 .Where(..
2c00: 20 20 20 20 20 20 20 20 20 20 20 66 20 3d 3e 20 f =>
2c10: 66 2e 4f 72 64 65 72 73 2e 41 6e 79 28 29 29 2e f.Orders.Any()).
2c20: 4f 72 64 65 72 42 79 28 0d 0a 20 20 20 20 20 20 OrderBy(..
2c30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 66 20 f
2c40: 3d 3e 20 66 2e 43 6f 6d 70 61 6e 79 4e 61 6d 65 => f.CompanyName
2c50: 29 2e 53 6b 69 70 28 31 29 2e 54 61 6b 65 28 31 ).Skip(1).Take(1
2c60: 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 );....
2c70: 20 20 20 20 76 61 72 20 63 75 73 74 6f 6d 65 72 var customer
2c80: 73 33 20 3d 20 64 62 2e 43 75 73 74 6f 6d 65 72 s3 = db.Customer
2c90: 73 2e 57 68 65 72 65 28 0d 0a 20 20 20 20 20 20 s.Where(..
2ca0: 20 20 20 20 20 20 20 20 20 20 20 20 66 20 3d 3e f =>
2cb0: 20 66 2e 43 75 73 74 6f 6d 65 72 49 44 2e 53 74 f.CustomerID.St
2cc0: 61 72 74 73 57 69 74 68 28 22 42 22 29 29 2e 4f artsWith("B")).O
2cd0: 72 64 65 72 42 79 28 0d 0a 20 20 20 20 20 20 20 rderBy(..
2ce0: 20 20 20 20 20 20 20 20 20 20 20 20 20 66 20 3d f =
2cf0: 3e 20 66 2e 43 6f 6d 70 61 6e 79 4e 61 6d 65 29 > f.CompanyName)
2d00: 2e 53 6b 69 70 28 31 29 2e 54 61 6b 65 28 31 29 .Skip(1).Take(1)
2d10: 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ;....
2d20: 20 20 20 66 6f 72 65 61 63 68 20 28 76 61 72 20 foreach (var
2d30: 63 75 73 74 6f 6d 65 72 20 69 6e 20 63 75 73 74 customer in cust
2d40: 6f 6d 65 72 73 31 29 0d 0a 20 20 20 20 20 20 20 omers1)..
2d50: 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 {..
2d60: 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20 28 if (
2d70: 6f 6e 63 65 29 0d 0a 20 20 20 20 20 20 20 20 20 once)..
2d80: 20 20 20 20 20 20 20 20 20 20 20 20 20 43 6f 6e Con
2d90: 73 6f 6c 65 2e 57 72 69 74 65 28 27 20 27 29 3b sole.Write(' ');
2da0: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 ....
2db0: 20 20 20 20 20 20 43 6f 6e 73 6f 6c 65 2e 57 72 Console.Wr
2dc0: 69 74 65 28 63 75 73 74 6f 6d 65 72 2e 43 75 73 ite(customer.Cus
2dd0: 74 6f 6d 65 72 49 44 29 3b 0d 0a 20 20 20 20 20 tomerID);..
2de0: 20 20 20 20 20 20 20 20 20 20 20 20 20 6f 6e 63 onc
2df0: 65 20 3d 20 74 72 75 65 3b 0d 0a 20 20 20 20 20 e = true;..
2e00: 20 20 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 }....
2e10: 20 20 20 20 20 20 20 20 20 20 20 20 66 6f 72 65 fore
2e20: 61 63 68 20 28 76 61 72 20 63 75 73 74 6f 6d 65 ach (var custome
2e30: 72 20 69 6e 20 63 75 73 74 6f 6d 65 72 73 32 29 r in customers2)
2e40: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
2e50: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 {..
2e60: 20 20 20 20 20 69 66 20 28 6f 6e 63 65 29 0d 0a if (once)..
2e70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2e80: 20 20 20 20 20 20 43 6f 6e 73 6f 6c 65 2e 57 72 Console.Wr
2e90: 69 74 65 28 27 20 27 29 3b 0d 0a 0d 0a 20 20 20 ite(' ');....
2ea0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 43 C
2eb0: 6f 6e 73 6f 6c 65 2e 57 72 69 74 65 28 63 75 73 onsole.Write(cus
2ec0: 74 6f 6d 65 72 2e 43 75 73 74 6f 6d 65 72 49 44 tomer.CustomerID
2ed0: 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 );..
2ee0: 20 20 20 20 20 20 6f 6e 63 65 20 3d 20 74 72 75 once = tru
2ef0: 65 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 e;..
2f00: 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 }....
2f10: 20 20 20 20 20 66 6f 72 65 61 63 68 20 28 76 61 foreach (va
2f20: 72 20 63 75 73 74 6f 6d 65 72 20 69 6e 20 63 75 r customer in cu
2f30: 73 74 6f 6d 65 72 73 33 29 0d 0a 20 20 20 20 20 stomers3)..
2f40: 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 {..
2f50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 66 if
2f60: 20 28 6f 6e 63 65 29 0d 0a 20 20 20 20 20 20 20 (once)..
2f70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 43 C
2f80: 6f 6e 73 6f 6c 65 2e 57 72 69 74 65 28 27 20 27 onsole.Write(' '
2f90: 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 );....
2fa0: 20 20 20 20 20 20 20 20 43 6f 6e 73 6f 6c 65 2e Console.
2fb0: 57 72 69 74 65 28 63 75 73 74 6f 6d 65 72 2e 43 Write(customer.C
2fc0: 75 73 74 6f 6d 65 72 49 44 29 3b 0d 0a 20 20 20 ustomerID);..
2fd0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 6f o
2fe0: 6e 63 65 20 3d 20 74 72 75 65 3b 0d 0a 20 20 20 nce = true;..
2ff0: 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 0d 0a }....
3000: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 66 6f fo
3010: 72 65 61 63 68 20 28 76 61 72 20 63 75 73 74 6f reach (var custo
3020: 6d 65 72 20 69 6e 20 63 75 73 74 6f 6d 65 72 73 mer in customers
3030: 31 2e 43 6f 6e 63 61 74 28 63 75 73 74 6f 6d 65 1.Concat(custome
3040: 72 73 32 29 29 0d 0a 20 20 20 20 20 20 20 20 20 rs2))..
3050: 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 {..
3060: 20 20 20 20 20 20 20 20 20 20 69 66 20 28 6f 6e if (on
3070: 63 65 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ce)..
3080: 20 20 20 20 20 20 20 20 20 20 20 43 6f 6e 73 6f Conso
3090: 6c 65 2e 57 72 69 74 65 28 27 20 27 29 3b 0d 0a le.Write(' ');..
30a0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
30b0: 20 20 20 20 43 6f 6e 73 6f 6c 65 2e 57 72 69 74 Console.Writ
30c0: 65 28 63 75 73 74 6f 6d 65 72 2e 43 75 73 74 6f e(customer.Custo
30d0: 6d 65 72 49 44 29 3b 0d 0a 20 20 20 20 20 20 20 merID);..
30e0: 20 20 20 20 20 20 20 20 20 20 20 6f 6e 63 65 20 once
30f0: 3d 20 74 72 75 65 3b 0d 0a 20 20 20 20 20 20 20 = true;..
3100: 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 }....
3110: 20 20 20 20 20 20 20 20 20 20 66 6f 72 65 61 63 foreac
3120: 68 20 28 76 61 72 20 63 75 73 74 6f 6d 65 72 20 h (var customer
3130: 69 6e 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 in..
3140: 20 20 20 20 20 20 20 20 63 75 73 74 6f 6d 65 72 customer
3150: 73 31 2e 43 6f 6e 63 61 74 28 63 75 73 74 6f 6d s1.Concat(custom
3160: 65 72 73 32 29 2e 43 6f 6e 63 61 74 28 63 75 73 ers2).Concat(cus
3170: 74 6f 6d 65 72 73 33 29 29 0d 0a 20 20 20 20 20 tomers3))..
3180: 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 {..
3190: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 66 if
31a0: 20 28 6f 6e 63 65 29 0d 0a 20 20 20 20 20 20 20 (once)..
31b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 43 C
31c0: 6f 6e 73 6f 6c 65 2e 57 72 69 74 65 28 27 20 27 onsole.Write(' '
31d0: 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 );....
31e0: 20 20 20 20 20 20 20 20 43 6f 6e 73 6f 6c 65 2e Console.
31f0: 57 72 69 74 65 28 63 75 73 74 6f 6d 65 72 2e 43 Write(customer.C
3200: 75 73 74 6f 6d 65 72 49 44 29 3b 0d 0a 20 20 20 ustomerID);..
3210: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 6f o
3220: 6e 63 65 20 3d 20 74 72 75 65 3b 0d 0a 20 20 20 nce = true;..
3230: 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 }..
3240: 20 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 }....
3250: 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 30 3b return 0;
3260: 0d 0a 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 .. }....
3270: 20 20 20 2f 2f 0d 0a 20 20 20 20 20 20 2f 2f 20 //.. //
3280: 4e 4f 54 45 3a 20 55 73 65 64 20 74 6f 20 74 65 NOTE: Used to te
3290: 73 74 20 74 68 65 20 66 69 78 20 66 6f 72 20 74 st the fix for t
32a0: 69 63 6b 65 74 20 5b 63 63 66 61 36 39 66 63 33 icket [ccfa69fc3
32b0: 32 5d 2e 0d 0a 20 20 20 20 20 20 2f 2f 0d 0a 20 2]... //..
32c0: 20 20 20 20 20 70 72 69 76 61 74 65 20 73 74 61 private sta
32d0: 74 69 63 20 69 6e 74 20 45 46 54 72 61 6e 73 61 tic int EFTransa
32e0: 63 74 69 6f 6e 54 65 73 74 28 62 6f 6f 6c 20 61 ctionTest(bool a
32f0: 64 64 29 0d 0a 20 20 20 20 20 20 7b 0d 0a 20 20 dd).. {..
3300: 20 20 20 20 20 20 20 20 2f 2f 0d 0a 20 20 20 20 //..
3310: 20 20 20 20 20 20 2f 2f 20 4e 4f 54 45 3a 20 53 // NOTE: S
3320: 6f 6d 65 20 6f 66 20 74 68 65 73 65 20 74 65 72 ome of these ter
3330: 72 69 74 6f 72 69 65 73 20 61 6c 72 65 61 64 79 ritories already
3340: 20 65 78 69 73 74 20 61 6e 64 20 73 68 6f 75 6c exist and shoul
3350: 64 20 63 61 75 73 65 0d 0a 20 20 20 20 20 20 20 d cause..
3360: 20 20 20 2f 2f 20 20 20 20 20 20 20 61 6e 20 65 // an e
3370: 78 63 65 70 74 69 6f 6e 20 74 6f 20 62 65 20 74 xception to be t
3380: 68 72 6f 77 6e 20 77 68 65 6e 20 77 65 20 74 72 hrown when we tr
3390: 79 20 74 6f 20 49 4e 53 45 52 54 20 74 68 65 6d y to INSERT them
33a0: 2e 0d 0a 20 20 20 20 20 20 20 20 20 20 2f 2f 0d ... //.
33b0: 0a 20 20 20 20 20 20 20 20 20 20 6c 6f 6e 67 5b . long[
33c0: 5d 20 74 65 72 72 69 74 6f 72 79 49 64 73 20 3d ] territoryIds =
33d0: 20 6e 65 77 20 6c 6f 6e 67 5b 5d 20 7b 0d 0a 20 new long[] {..
33e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
33f0: 31 2c 20 20 20 20 32 2c 20 20 20 20 33 2c 20 20 1, 2, 3,
3400: 20 20 34 2c 20 20 20 20 35 2c 20 2f 2f 20 4e 4f 4, 5, // NO
3410: 54 45 3a 20 53 75 63 63 65 73 73 0d 0a 20 20 20 TE: Success..
3420: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 36 2c 6,
3430: 20 20 20 20 37 2c 20 20 20 20 38 2c 20 20 20 20 7, 8,
3440: 39 2c 20 20 20 31 30 2c 20 2f 2f 20 4e 4f 54 45 9, 10, // NOTE
3450: 3a 20 53 75 63 63 65 73 73 0d 0a 20 20 20 20 20 : Success..
3460: 20 20 20 20 20 20 20 20 20 31 35 37 36 2c 20 31 1576, 1
3470: 35 37 37 2c 20 31 35 37 38 2c 20 31 35 37 39 2c 577, 1578, 1579,
3480: 20 31 35 38 30 2c 20 2f 2f 20 4e 4f 54 45 3a 20 1580, // NOTE:
3490: 53 75 63 63 65 73 73 0d 0a 20 20 20 20 20 20 20 Success..
34a0: 20 20 20 20 20 20 20 31 35 38 31 2c 20 31 37 33 1581, 173
34b0: 30 2c 20 31 38 33 33 2c 20 32 31 31 36 2c 20 32 0, 1833, 2116, 2
34c0: 31 33 39 2c 20 2f 2f 20 4e 4f 54 45 3a 20 46 61 139, // NOTE: Fa
34d0: 69 6c 20 28 31 35 38 31 29 0d 0a 20 20 20 20 20 il (1581)..
34e0: 20 20 20 20 20 20 20 20 20 32 31 34 30 2c 20 32 2140, 2
34f0: 31 34 31 20 20 20 20 20 20 20 20 20 20 20 20 20 141
3500: 20 20 20 20 20 20 20 2f 2f 20 4e 4f 54 45 3a 20 // NOTE:
3510: 53 6b 69 70 70 65 64 0d 0a 20 20 20 20 20 20 20 Skipped..
3520: 20 20 20 7d 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 };....
3530: 20 20 20 69 66 20 28 61 64 64 29 0d 0a 20 20 20 if (add)..
3540: 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 {..
3550: 20 20 20 20 20 20 20 20 75 73 69 6e 67 20 28 6e using (n
3560: 6f 72 74 68 77 69 6e 64 45 46 45 6e 74 69 74 69 orthwindEFEntiti
3570: 65 73 20 64 62 20 3d 20 6e 65 77 20 6e 6f 72 74 es db = new nort
3580: 68 77 69 6e 64 45 46 45 6e 74 69 74 69 65 73 28 hwindEFEntities(
3590: 29 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 ))..
35a0: 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 {..
35b0: 20 20 20 20 20 20 20 75 73 69 6e 67 20 28 54 72 using (Tr
35c0: 61 6e 73 61 63 74 69 6f 6e 53 63 6f 70 65 20 73 ansactionScope s
35d0: 63 6f 70 65 20 3d 20 6e 65 77 20 54 72 61 6e 73 cope = new Trans
35e0: 61 63 74 69 6f 6e 53 63 6f 70 65 28 29 29 0d 0a actionScope())..
35f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3600: 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 {..
3610: 20 20 20 20 20 20 20 20 20 20 20 2f 2f 0d 0a 20 //..
3620: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3630: 20 20 20 20 20 2f 2f 20 4e 4f 54 45 3a 20 2a 52 // NOTE: *R
3640: 45 51 55 49 52 45 44 2a 20 54 68 69 73 20 69 73 EQUIRED* This is
3650: 20 72 65 71 75 69 72 65 64 20 73 6f 20 74 68 61 required so tha
3660: 74 20 74 68 65 0d 0a 20 20 20 20 20 20 20 20 20 t the..
3670: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 //
3680: 20 20 20 20 20 20 45 6e 74 69 74 79 20 46 72 61 Entity Fra
3690: 6d 65 77 6f 72 6b 20 69 73 20 70 72 65 76 65 6e mework is preven
36a0: 74 65 64 20 66 72 6f 6d 20 6f 70 65 6e 69 6e 67 ted from opening
36b0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
36c0: 20 20 20 20 20 20 20 20 2f 2f 20 20 20 20 20 20 //
36d0: 20 6d 75 6c 74 69 70 6c 65 20 63 6f 6e 6e 65 63 multiple connec
36e0: 74 69 6f 6e 73 20 74 6f 20 74 68 65 20 75 6e 64 tions to the und
36f0: 65 72 6c 79 69 6e 67 20 53 51 4c 69 74 65 0d 0a erlying SQLite..
3700: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3710: 20 20 20 20 20 20 2f 2f 20 20 20 20 20 20 20 64 // d
3720: 61 74 61 62 61 73 65 20 28 69 2e 65 2e 20 77 68 atabase (i.e. wh
3730: 69 63 68 20 77 6f 75 6c 64 20 72 65 73 75 6c 74 ich would result
3740: 20 69 6e 20 6d 75 6c 74 69 70 6c 65 0d 0a 20 20 in multiple..
3750: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3760: 20 20 20 20 2f 2f 20 20 20 20 20 20 20 49 4d 4d // IMM
3770: 45 44 49 41 54 45 20 74 72 61 6e 73 61 63 74 69 EDIATE transacti
3780: 6f 6e 73 2c 20 74 68 65 72 65 62 79 20 66 61 69 ons, thereby fai
3790: 6c 69 6e 67 20 5b 6c 61 74 65 72 0d 0a 20 20 20 ling [later..
37a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
37b0: 20 20 20 2f 2f 20 20 20 20 20 20 20 6f 6e 5d 20 // on]
37c0: 77 69 74 68 20 6c 6f 63 6b 69 6e 67 20 65 72 72 with locking err
37d0: 6f 72 73 29 2e 0d 0a 20 20 20 20 20 20 20 20 20 ors)...
37e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 0d //.
37f0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
3800: 20 20 20 20 20 20 20 64 62 2e 43 6f 6e 6e 65 63 db.Connec
3810: 74 69 6f 6e 2e 4f 70 65 6e 28 29 3b 0d 0a 0d 0a tion.Open();....
3820: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3830: 20 20 20 20 20 20 66 6f 72 65 61 63 68 20 28 69 foreach (i
3840: 6e 74 20 69 64 20 69 6e 20 74 65 72 72 69 74 6f nt id in territo
3850: 72 79 49 64 73 29 0d 0a 20 20 20 20 20 20 20 20 ryIds)..
3860: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7b 0d {.
3870: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
3880: 20 20 20 20 20 20 20 20 20 20 20 54 65 72 72 69 Terri
3890: 74 6f 72 69 65 73 20 74 65 72 72 69 74 6f 72 69 tories territori
38a0: 65 73 20 3d 20 6e 65 77 20 54 65 72 72 69 74 6f es = new Territo
38b0: 72 69 65 73 28 29 3b 0d 0a 0d 0a 20 20 20 20 20 ries();....
38c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
38d0: 20 20 20 20 20 74 65 72 72 69 74 6f 72 69 65 73 territories
38e0: 2e 54 65 72 72 69 74 6f 72 79 49 44 20 3d 20 69 .TerritoryID = i
38f0: 64 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 d;..
3900: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 74 65 te
3910: 72 72 69 74 6f 72 69 65 73 2e 54 65 72 72 69 74 rritories.Territ
3920: 6f 72 79 44 65 73 63 72 69 70 74 69 6f 6e 20 3d oryDescription =
3930: 20 53 74 72 69 6e 67 2e 46 6f 72 6d 61 74 28 0d String.Format(.
3940: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
3950: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 "
3960: 54 65 73 74 20 54 65 72 72 69 74 6f 72 79 20 23 Test Territory #
3970: 7b 30 7d 22 2c 20 69 64 29 3b 0d 0a 20 20 20 20 {0}", id);..
3980: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3990: 20 20 20 20 20 20 74 65 72 72 69 74 6f 72 69 65 territorie
39a0: 73 2e 52 65 67 69 6f 6e 73 20 3d 20 64 62 2e 52 s.Regions = db.R
39b0: 65 67 69 6f 6e 73 2e 46 69 72 73 74 28 29 3b 0d egions.First();.
39c0: 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ...
39d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 64 62 2e db.
39e0: 41 64 64 4f 62 6a 65 63 74 28 22 54 65 72 72 69 AddObject("Terri
39f0: 74 6f 72 69 65 73 22 2c 20 74 65 72 72 69 74 6f tories", territo
3a00: 72 69 65 73 29 3b 0d 0a 20 20 20 20 20 20 20 20 ries);..
3a10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d }.
3a20: 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ...
3a30: 20 20 20 20 20 20 20 20 20 74 72 79 0d 0a 20 20 try..
3a40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3a50: 20 20 20 20 7b 0d 0a 23 69 66 20 4e 45 54 5f 34 {..#if NET_4
3a60: 30 20 7c 7c 20 4e 45 54 5f 34 35 20 7c 7c 20 4e 0 || NET_45 || N
3a70: 45 54 5f 34 35 31 0d 0a 20 20 20 20 20 20 20 20 ET_451..
3a80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3a90: 20 20 64 62 2e 53 61 76 65 43 68 61 6e 67 65 73 db.SaveChanges
3aa0: 28 53 61 76 65 4f 70 74 69 6f 6e 73 2e 4e 6f 6e (SaveOptions.Non
3ab0: 65 29 3b 0d 0a 23 65 6c 73 65 0d 0a 20 20 20 20 e);..#else..
3ac0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3ad0: 20 20 20 20 20 20 64 62 2e 53 61 76 65 43 68 61 db.SaveCha
3ae0: 6e 67 65 73 28 66 61 6c 73 65 29 3b 0d 0a 23 65 nges(false);..#e
3af0: 6e 64 69 66 0d 0a 20 20 20 20 20 20 20 20 20 20 ndif..
3b00: 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 }..
3b10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3b20: 20 20 20 20 20 63 61 74 63 68 20 28 45 78 63 65 catch (Exce
3b30: 70 74 69 6f 6e 20 65 29 0d 0a 20 20 20 20 20 20 ption e)..
3b40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3b50: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 {..
3b60: 20 20 20 20 20 20 20 20 20 20 20 20 20 43 6f 6e Con
3b70: 73 6f 6c 65 2e 57 72 69 74 65 4c 69 6e 65 28 65 sole.WriteLine(e
3b80: 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 );..
3b90: 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 }..
3ba0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3bb0: 20 20 20 66 69 6e 61 6c 6c 79 0d 0a 20 20 20 20 finally..
3bc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3bd0: 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 {..
3be0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 73 s
3bf0: 63 6f 70 65 2e 43 6f 6d 70 6c 65 74 65 28 29 3b cope.Complete();
3c00: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
3c10: 20 20 20 20 20 20 20 20 20 20 20 20 64 62 2e 41 db.A
3c20: 63 63 65 70 74 41 6c 6c 43 68 61 6e 67 65 73 28 cceptAllChanges(
3c30: 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 );..
3c40: 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 }..
3c50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d }
3c60: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
3c70: 7d 0d 0a 20 20 20 20 20 20 20 20 20 20 7d 0d 0a }.. }..
3c80: 20 20 20 20 20 20 20 20 20 20 65 6c 73 65 0d 0a else..
3c90: 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 {..
3ca0: 20 20 20 20 20 20 20 20 20 20 20 75 73 69 6e 67 using
3cb0: 20 28 6e 6f 72 74 68 77 69 6e 64 45 46 45 6e 74 (northwindEFEnt
3cc0: 69 74 69 65 73 20 64 62 20 3d 20 6e 65 77 20 6e ities db = new n
3cd0: 6f 72 74 68 77 69 6e 64 45 46 45 6e 74 69 74 69 orthwindEFEntiti
3ce0: 65 73 28 29 29 0d 0a 20 20 20 20 20 20 20 20 20 es())..
3cf0: 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 {..
3d00: 20 20 20 20 20 20 20 20 20 20 62 6f 6f 6c 20 6f bool o
3d10: 6e 63 65 20 3d 20 66 61 6c 73 65 3b 0d 0a 23 69 nce = false;..#i
3d20: 66 20 4e 45 54 5f 34 30 20 7c 7c 20 4e 45 54 5f f NET_40 || NET_
3d30: 34 35 20 7c 7c 20 4e 45 54 5f 34 35 31 0d 0a 20 45 || NET_451..
3d40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3d50: 20 76 61 72 20 71 75 65 72 79 20 3d 20 66 72 6f var query = fro
3d60: 6d 20 74 20 69 6e 20 64 62 2e 54 65 72 72 69 74 m t in db.Territ
3d70: 6f 72 69 65 73 0d 0a 20 20 20 20 20 20 20 20 20 ories..
3d80: 20 20 20 20 20 20 20 20 20 20 20 77 68 65 72 65 where
3d90: 20 74 65 72 72 69 74 6f 72 79 49 64 73 2e 41 73 territoryIds.As
3da0: 51 75 65 72 79 61 62 6c 65 3c 6c 6f 6e 67 3e 28 Queryable<long>(
3db0: 29 2e 43 6f 6e 74 61 69 6e 73 3c 6c 6f 6e 67 3e ).Contains<long>
3dc0: 28 74 2e 54 65 72 72 69 74 6f 72 79 49 44 29 0d (t.TerritoryID).
3dd0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
3de0: 20 20 20 20 20 6f 72 64 65 72 62 79 20 74 2e 54 orderby t.T
3df0: 65 72 72 69 74 6f 72 79 49 44 0d 0a 20 20 20 20 erritoryID..
3e00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3e10: 73 65 6c 65 63 74 20 74 3b 0d 0a 0d 0a 20 20 20 select t;....
3e20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 66 f
3e30: 6f 72 65 61 63 68 20 28 54 65 72 72 69 74 6f 72 oreach (Territor
3e40: 69 65 73 20 74 65 72 72 69 74 6f 72 69 65 73 20 ies territories
3e50: 69 6e 20 71 75 65 72 79 29 0d 0a 20 20 20 20 20 in query)..
3e60: 20 20 20 20 20 20 20 20 20 20 20 20 20 7b 0d 0a {..
3e70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3e80: 20 20 20 20 20 20 69 66 20 28 6f 6e 63 65 29 0d if (once).
3e90: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
3ea0: 20 20 20 20 20 20 20 20 20 20 20 43 6f 6e 73 6f Conso
3eb0: 6c 65 2e 57 72 69 74 65 28 27 20 27 29 3b 0d 0a le.Write(' ');..
3ec0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
3ed0: 20 20 20 20 20 20 20 20 43 6f 6e 73 6f 6c 65 2e Console.
3ee0: 57 72 69 74 65 28 74 65 72 72 69 74 6f 72 69 65 Write(territorie
3ef0: 73 2e 54 65 72 72 69 74 6f 72 79 49 44 29 3b 0d s.TerritoryID);.
3f00: 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ...
3f10: 20 20 20 20 20 20 20 20 20 6f 6e 63 65 20 3d 20 once =
3f20: 74 72 75 65 3b 0d 0a 20 20 20 20 20 20 20 20 20 true;..
3f30: 20 20 20 20 20 20 20 20 20 7d 0d 0a 23 65 6c 73 }..#els
3f40: 65 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 e..
3f50: 20 20 20 20 20 2f 2f 0d 0a 20 20 20 20 20 20 20 //..
3f60: 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 48 41 // HA
3f70: 43 4b 3a 20 57 65 20 63 61 6e 6e 6f 74 20 75 73 CK: We cannot us
3f80: 65 20 74 68 65 20 43 6f 6e 74 61 69 6e 73 20 65 e the Contains e
3f90: 78 74 65 6e 73 69 6f 6e 20 6d 65 74 68 6f 64 20 xtension method
3fa0: 77 69 74 68 69 6e 20 61 0d 0a 20 20 20 20 20 20 within a..
3fb0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 20 //
3fc0: 20 20 20 20 20 4c 49 4e 51 20 71 75 65 72 79 20 LINQ query
3fd0: 77 69 74 68 20 74 68 65 20 2e 4e 45 54 20 46 72 with the .NET Fr
3fe0: 61 6d 65 77 6f 72 6b 20 33 2e 35 2e 0d 0a 20 20 amework 3.5...
3ff0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
4000: 2f 2f 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 //..
4010: 20 20 20 20 20 20 76 61 72 20 71 75 65 72 79 20 var query
4020: 3d 20 66 72 6f 6d 20 74 20 69 6e 20 64 62 2e 54 = from t in db.T
4030: 65 72 72 69 74 6f 72 69 65 73 0d 0a 20 20 20 20 erritories..
4040: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
4050: 6f 72 64 65 72 62 79 20 74 2e 54 65 72 72 69 74 orderby t.Territ
4060: 6f 72 79 49 44 0d 0a 20 20 20 20 20 20 20 20 20 oryID..
4070: 20 20 20 20 20 20 20 20 20 20 20 73 65 6c 65 63 selec
4080: 74 20 74 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 t t;....
4090: 20 20 20 20 20 20 20 20 20 20 66 6f 72 65 61 63 foreac
40a0: 68 20 28 54 65 72 72 69 74 6f 72 69 65 73 20 74 h (Territories t
40b0: 65 72 72 69 74 6f 72 69 65 73 20 69 6e 20 71 75 erritories in qu
40c0: 65 72 79 29 0d 0a 20 20 20 20 20 20 20 20 20 20 ery)..
40d0: 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 {..
40e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
40f0: 20 69 66 20 28 41 72 72 61 79 2e 49 6e 64 65 78 if (Array.Index
4100: 4f 66 28 74 65 72 72 69 74 6f 72 79 49 64 73 2c Of(territoryIds,
4110: 20 74 65 72 72 69 74 6f 72 69 65 73 2e 54 65 72 territories.Ter
4120: 72 69 74 6f 72 79 49 44 29 20 3d 3d 20 2d 31 29 ritoryID) == -1)
4130: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
4140: 20 20 20 20 20 20 20 20 20 20 20 20 63 6f 6e 74 cont
4150: 69 6e 75 65 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 inue;....
4160: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 i
4170: 66 20 28 6f 6e 63 65 29 0d 0a 20 20 20 20 20 20 f (once)..
4180: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
4190: 20 20 20 20 43 6f 6e 73 6f 6c 65 2e 57 72 69 74 Console.Writ
41a0: 65 28 27 20 27 29 3b 0d 0a 0d 0a 20 20 20 20 20 e(' ');....
41b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
41c0: 20 43 6f 6e 73 6f 6c 65 2e 57 72 69 74 65 28 74 Console.Write(t
41d0: 65 72 72 69 74 6f 72 69 65 73 2e 54 65 72 72 69 erritories.Terri
41e0: 74 6f 72 79 49 44 29 3b 0d 0a 0d 0a 20 20 20 20 toryID);....
41f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
4200: 20 20 6f 6e 63 65 20 3d 20 74 72 75 65 3b 0d 0a once = true;..
4210: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
4220: 20 20 7d 0d 0a 23 65 6e 64 69 66 0d 0a 20 20 20 }..#endif..
4230: 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 }..
4240: 20 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 }....
4250: 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 30 3b return 0;
4260: 0d 0a 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 .. }....
4270: 20 20 20 2f 2f 0d 0a 20 20 20 20 20 20 2f 2f 20 //.. //
4280: 4e 4f 54 45 3a 20 55 73 65 64 20 74 6f 20 74 65 NOTE: Used to te
4290: 73 74 20 74 68 65 20 49 4e 53 45 52 54 20 66 69 st the INSERT fi
42a0: 78 20 28 69 2e 65 2e 20 61 6e 20 65 78 74 72 61 x (i.e. an extra
42b0: 20 73 65 6d 69 2d 63 6f 6c 6f 6e 20 69 6e 0d 0a semi-colon in..
42c0: 20 20 20 20 20 20 2f 2f 20 20 20 20 20 20 20 74 // t
42d0: 68 65 20 53 51 4c 20 73 74 61 74 65 6d 65 6e 74 he SQL statement
42e0: 20 61 66 74 65 72 20 74 68 65 20 61 63 74 75 61 after the actua
42f0: 6c 20 49 4e 53 45 52 54 20 73 74 61 74 65 6d 65 l INSERT stateme
4300: 6e 74 20 69 6e 0d 0a 20 20 20 20 20 20 2f 2f 20 nt in.. //
4310: 20 20 20 20 20 20 74 68 65 20 66 6f 6c 6c 6f 77 the follow
4320: 2d 75 70 20 53 45 4c 45 43 54 20 73 74 61 74 65 -up SELECT state
4330: 6d 65 6e 74 29 2e 0d 0a 20 20 20 20 20 20 2f 2f ment)... //
4340: 0d 0a 20 20 20 20 20 20 70 72 69 76 61 74 65 20 .. private
4350: 73 74 61 74 69 63 20 69 6e 74 20 49 6e 73 65 72 static int Inser
4360: 74 54 65 73 74 28 29 0d 0a 20 20 20 20 20 20 7b tTest().. {
4370: 0d 0a 20 20 20 20 20 20 20 20 20 20 6c 6f 6e 67 .. long
4380: 5b 5d 20 6f 72 64 65 72 49 64 73 20 3d 20 6e 65 [] orderIds = ne
4390: 77 20 6c 6f 6e 67 5b 5d 20 7b 0d 0a 20 20 20 20 w long[] {..
43a0: 20 20 20 20 20 20 20 20 20 20 30 0d 0a 20 20 20 0..
43b0: 20 20 20 20 20 20 20 7d 3b 0d 0a 0d 0a 20 20 20 };....
43c0: 20 20 20 20 20 20 20 75 73 69 6e 67 20 28 6e 6f using (no
43d0: 72 74 68 77 69 6e 64 45 46 45 6e 74 69 74 69 65 rthwindEFEntitie
43e0: 73 20 64 62 20 3d 20 6e 65 77 20 6e 6f 72 74 68 s db = new north
43f0: 77 69 6e 64 45 46 45 6e 74 69 74 69 65 73 28 29 windEFEntities()
4400: 29 0d 0a 20 20 20 20 20 20 20 20 20 20 7b 0d 0a ).. {..
4410: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 6e in
4420: 74 5b 5d 20 63 6f 75 6e 74 73 20 3d 20 7b 20 30 t[] counts = { 0
4430: 20 7d 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 };....
4440: 20 20 20 20 20 2f 2f 0d 0a 20 20 20 20 20 20 20 //..
4450: 20 20 20 20 20 20 20 2f 2f 20 4e 4f 54 45 3a 20 // NOTE:
4460: 2a 52 45 51 55 49 52 45 44 2a 20 54 68 69 73 20 *REQUIRED* This
4470: 69 73 20 72 65 71 75 69 72 65 64 20 73 6f 20 74 is required so t
4480: 68 61 74 20 74 68 65 0d 0a 20 20 20 20 20 20 20 hat the..
4490: 20 20 20 20 20 20 20 2f 2f 20 20 20 20 20 20 20 //
44a0: 45 6e 74 69 74 79 20 46 72 61 6d 65 77 6f 72 6b Entity Framework
44b0: 20 69 73 20 70 72 65 76 65 6e 74 65 64 20 66 72 is prevented fr
44c0: 6f 6d 20 6f 70 65 6e 69 6e 67 0d 0a 20 20 20 20 om opening..
44d0: 20 20 20 20 20 20 20 20 20 20 2f 2f 20 20 20 20 //
44e0: 20 20 20 6d 75 6c 74 69 70 6c 65 20 63 6f 6e 6e multiple conn
44f0: 65 63 74 69 6f 6e 73 20 74 6f 20 74 68 65 20 75 ections to the u
4500: 6e 64 65 72 6c 79 69 6e 67 20 53 51 4c 69 74 65 nderlying SQLite
4510: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
4520: 2f 2f 20 20 20 20 20 20 20 64 61 74 61 62 61 73 // databas
4530: 65 20 28 69 2e 65 2e 20 77 68 69 63 68 20 77 6f e (i.e. which wo
4540: 75 6c 64 20 72 65 73 75 6c 74 20 69 6e 20 6d 75 uld result in mu
4550: 6c 74 69 70 6c 65 0d 0a 20 20 20 20 20 20 20 20 ltiple..
4560: 20 20 20 20 20 20 2f 2f 20 20 20 20 20 20 20 49 // I
4570: 4d 4d 45 44 49 41 54 45 20 74 72 61 6e 73 61 63 MMEDIATE transac
4580: 74 69 6f 6e 73 2c 20 74 68 65 72 65 62 79 20 66 tions, thereby f
4590: 61 69 6c 69 6e 67 20 5b 6c 61 74 65 72 0d 0a 20 ailing [later..
45a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 //
45b0: 20 20 20 20 20 20 6f 6e 5d 20 77 69 74 68 20 6c on] with l
45c0: 6f 63 6b 69 6e 67 20 65 72 72 6f 72 73 29 2e 0d ocking errors)..
45d0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f . /
45e0: 2f 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 /..
45f0: 20 64 62 2e 43 6f 6e 6e 65 63 74 69 6f 6e 2e 4f db.Connection.O
4600: 70 65 6e 28 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 pen();....
4610: 20 20 20 20 20 20 20 20 4f 72 64 65 72 44 65 74 OrderDet
4620: 61 69 6c 73 20 6e 65 77 4f 72 64 65 72 44 65 74 ails newOrderDet
4630: 61 69 6c 73 20 3d 20 6e 65 77 20 4f 72 64 65 72 ails = new Order
4640: 44 65 74 61 69 6c 73 28 29 3b 0d 0a 0d 0a 20 20 Details();....
4650: 20 20 20 20 20 20 20 20 20 20 20 20 6e 65 77 4f newO
4660: 72 64 65 72 44 65 74 61 69 6c 73 2e 4f 72 64 65 rderDetails.Orde
4670: 72 49 44 20 3d 20 31 30 32 34 38 3b 0d 0a 20 20 rID = 10248;..
4680: 20 20 20 20 20 20 20 20 20 20 20 20 6e 65 77 4f newO
4690: 72 64 65 72 44 65 74 61 69 6c 73 2e 50 72 6f 64 rderDetails.Prod
46a0: 75 63 74 49 44 20 3d 20 31 3b 0d 0a 20 20 20 20 uctID = 1;..
46b0: 20 20 20 20 20 20 20 20 20 20 6e 65 77 4f 72 64 newOrd
46c0: 65 72 44 65 74 61 69 6c 73 2e 55 6e 69 74 50 72 erDetails.UnitPr
46d0: 69 63 65 20 3d 20 28 64 65 63 69 6d 61 6c 29 31 ice = (decimal)1
46e0: 2e 32 33 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 .23;..
46f0: 20 20 20 20 6e 65 77 4f 72 64 65 72 44 65 74 61 newOrderDeta
4700: 69 6c 73 2e 51 75 61 6e 74 69 74 79 20 3d 20 31 ils.Quantity = 1
4710: 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ;..
4720: 20 6e 65 77 4f 72 64 65 72 44 65 74 61 69 6c 73 newOrderDetails
4730: 2e 44 69 73 63 6f 75 6e 74 20 3d 20 30 2e 30 66 .Discount = 0.0f
4740: 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ;....
4750: 20 20 20 64 62 2e 41 64 64 4f 62 6a 65 63 74 28 db.AddObject(
4760: 22 4f 72 64 65 72 44 65 74 61 69 6c 73 22 2c 20 "OrderDetails",
4770: 6e 65 77 4f 72 64 65 72 44 65 74 61 69 6c 73 29 newOrderDetails)
4780: 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ;....
4790: 20 20 20 74 72 79 0d 0a 20 20 20 20 20 20 20 20 try..
47a0: 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 {..
47b0: 20 20 20 20 20 20 20 20 20 20 20 64 62 2e 53 61 db.Sa
47c0: 76 65 43 68 61 6e 67 65 73 28 29 3b 0d 0a 20 20 veChanges();..
47d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
47e0: 63 6f 75 6e 74 73 5b 30 5d 2b 2b 3b 0d 0a 20 20 counts[0]++;..
47f0: 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 }..
4800: 20 20 20 20 20 20 20 20 20 20 20 20 20 63 61 74 cat
4810: 63 68 20 28 45 78 63 65 70 74 69 6f 6e 20 65 29 ch (Exception e)
4820: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
4830: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 {..
4840: 20 20 20 20 20 43 6f 6e 73 6f 6c 65 2e 57 72 69 Console.Wri
4850: 74 65 4c 69 6e 65 28 65 29 3b 0d 0a 20 20 20 20 teLine(e);..
4860: 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 }..
4870: 20 20 20 20 20 20 20 20 20 20 20 66 69 6e 61 6c final
4880: 6c 79 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 ly..
4890: 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 {..
48a0: 20 20 20 20 20 20 20 64 62 2e 41 63 63 65 70 74 db.Accept
48b0: 41 6c 6c 43 68 61 6e 67 65 73 28 29 3b 0d 0a 20 AllChanges();..
48c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a }..
48d0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
48e0: 43 6f 6e 73 6f 6c 65 2e 57 72 69 74 65 4c 69 6e Console.WriteLin
48f0: 65 28 22 69 6e 73 65 72 74 65 64 20 7b 30 7d 22 e("inserted {0}"
4900: 2c 20 63 6f 75 6e 74 73 5b 30 5d 29 3b 0d 0a 20 , counts[0]);..
4910: 20 20 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 }....
4920: 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 30 return 0
4930: 3b 0d 0a 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 ;.. }....
4940: 20 20 20 20 2f 2f 0d 0a 20 20 20 20 20 20 2f 2f //.. //
4950: 20 4e 4f 54 45 3a 20 55 73 65 64 20 74 6f 20 74 NOTE: Used to t
4960: 65 73 74 20 74 68 65 20 55 50 44 41 54 45 20 66 est the UPDATE f
4970: 69 78 20 28 69 2e 65 2e 20 74 68 65 20 6d 69 73 ix (i.e. the mis
4980: 73 69 6e 67 20 73 65 6d 69 2d 63 6f 6c 6f 6e 0d sing semi-colon.
4990: 0a 20 20 20 20 20 20 2f 2f 20 20 20 20 20 20 20 . //
49a0: 69 6e 20 74 68 65 20 53 51 4c 20 73 74 61 74 65 in the SQL state
49b0: 6d 65 6e 74 20 62 65 74 77 65 65 6e 20 74 68 65 ment between the
49c0: 20 61 63 74 75 61 6c 20 55 50 44 41 54 45 20 73 actual UPDATE s
49d0: 74 61 74 65 6d 65 6e 74 0d 0a 20 20 20 20 20 20 tatement..
49e0: 2f 2f 20 20 20 20 20 20 20 61 6e 64 20 74 68 65 // and the
49f0: 20 66 6f 6c 6c 6f 77 2d 75 70 20 53 45 4c 45 43 follow-up SELEC
4a00: 54 20 73 74 61 74 65 6d 65 6e 74 29 2e 0d 0a 20 T statement)...
4a10: 20 20 20 20 20 2f 2f 0d 0a 20 20 20 20 20 20 70 //.. p
4a20: 72 69 76 61 74 65 20 73 74 61 74 69 63 20 69 6e rivate static in
4a30: 74 20 55 70 64 61 74 65 54 65 73 74 28 29 0d 0a t UpdateTest()..
4a40: 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 {..
4a50: 20 20 20 6c 6f 6e 67 5b 5d 20 6f 72 64 65 72 49 long[] orderI
4a60: 64 73 20 3d 20 6e 65 77 20 6c 6f 6e 67 5b 5d 20 ds = new long[]
4a70: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 {..
4a80: 20 30 0d 0a 20 20 20 20 20 20 20 20 20 20 7d 3b 0.. };
4a90: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 75 73 .... us
4aa0: 69 6e 67 20 28 6e 6f 72 74 68 77 69 6e 64 45 46 ing (northwindEF
4ab0: 45 6e 74 69 74 69 65 73 20 64 62 20 3d 20 6e 65 Entities db = ne
4ac0: 77 20 6e 6f 72 74 68 77 69 6e 64 45 46 45 6e 74 w northwindEFEnt
4ad0: 69 74 69 65 73 28 29 29 0d 0a 20 20 20 20 20 20 ities())..
4ae0: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 {..
4af0: 20 20 20 20 20 69 6e 74 5b 5d 20 63 6f 75 6e 74 int[] count
4b00: 73 20 3d 20 7b 20 30 2c 20 30 20 7d 3b 0d 0a 0d s = { 0, 0 };...
4b10: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f . /
4b20: 2f 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 /..
4b30: 20 2f 2f 20 4e 4f 54 45 3a 20 2a 52 45 51 55 49 // NOTE: *REQUI
4b40: 52 45 44 2a 20 54 68 69 73 20 69 73 20 72 65 71 RED* This is req
4b50: 75 69 72 65 64 20 73 6f 20 74 68 61 74 20 74 68 uired so that th
4b60: 65 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 e..
4b70: 20 2f 2f 20 20 20 20 20 20 20 45 6e 74 69 74 79 // Entity
4b80: 20 46 72 61 6d 65 77 6f 72 6b 20 69 73 20 70 72 Framework is pr
4b90: 65 76 65 6e 74 65 64 20 66 72 6f 6d 20 6f 70 65 evented from ope
4ba0: 6e 69 6e 67 0d 0a 20 20 20 20 20 20 20 20 20 20 ning..
4bb0: 20 20 20 20 2f 2f 20 20 20 20 20 20 20 6d 75 6c // mul
4bc0: 74 69 70 6c 65 20 63 6f 6e 6e 65 63 74 69 6f 6e tiple connection
4bd0: 73 20 74 6f 20 74 68 65 20 75 6e 64 65 72 6c 79 s to the underly
4be0: 69 6e 67 20 53 51 4c 69 74 65 0d 0a 20 20 20 20 ing SQLite..
4bf0: 20 20 20 20 20 20 20 20 20 20 2f 2f 20 20 20 20 //
4c00: 20 20 20 64 61 74 61 62 61 73 65 20 28 69 2e 65 database (i.e
4c10: 2e 20 77 68 69 63 68 20 77 6f 75 6c 64 20 72 65 . which would re
4c20: 73 75 6c 74 20 69 6e 20 6d 75 6c 74 69 70 6c 65 sult in multiple
4c30: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
4c40: 2f 2f 20 20 20 20 20 20 20 49 4d 4d 45 44 49 41 // IMMEDIA
4c50: 54 45 20 74 72 61 6e 73 61 63 74 69 6f 6e 73 2c TE transactions,
4c60: 20 74 68 65 72 65 62 79 20 66 61 69 6c 69 6e 67 thereby failing
4c70: 20 5b 6c 61 74 65 72 0d 0a 20 20 20 20 20 20 20 [later..
4c80: 20 20 20 20 20 20 20 2f 2f 20 20 20 20 20 20 20 //
4c90: 6f 6e 5d 20 77 69 74 68 20 6c 6f 63 6b 69 6e 67 on] with locking
4ca0: 20 65 72 72 6f 72 73 29 2e 0d 0a 20 20 20 20 20 errors)...
4cb0: 20 20 20 20 20 20 20 20 20 2f 2f 0d 0a 20 20 20 //..
4cc0: 20 20 20 20 20 20 20 20 20 20 20 64 62 2e 43 6f db.Co
4cd0: 6e 6e 65 63 74 69 6f 6e 2e 4f 70 65 6e 28 29 3b nnection.Open();
4ce0: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 ....
4cf0: 20 20 66 6f 72 20 28 69 6e 74 20 69 6e 64 65 78 for (int index
4d00: 20 3d 20 30 3b 20 69 6e 64 65 78 20 3c 20 6f 72 = 0; index < or
4d10: 64 65 72 49 64 73 2e 4c 65 6e 67 74 68 3b 20 69 derIds.Length; i
4d20: 6e 64 65 78 2b 2b 29 0d 0a 20 20 20 20 20 20 20 ndex++)..
4d30: 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 {..
4d40: 20 20 20 20 20 20 20 20 20 20 20 20 4f 72 64 65 Orde
4d50: 72 73 20 6e 65 77 4f 72 64 65 72 73 20 3d 20 6e rs newOrders = n
4d60: 65 77 20 4f 72 64 65 72 73 28 29 3b 0d 0a 0d 0a ew Orders();....
4d70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
4d80: 20 20 6e 65 77 4f 72 64 65 72 73 2e 53 68 69 70 newOrders.Ship
4d90: 41 64 64 72 65 73 73 20 3d 20 53 74 72 69 6e 67 Address = String
4da0: 2e 46 6f 72 6d 61 74 28 0d 0a 20 20 20 20 20 20 .Format(..
4db0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
4dc0: 22 54 65 73 74 20 4f 72 64 65 72 20 53 68 69 70 "Test Order Ship
4dd0: 20 41 64 64 72 65 73 73 2c 20 49 6e 64 65 78 20 Address, Index
4de0: 23 7b 30 7d 22 2c 0d 0a 20 20 20 20 20 20 20 20 #{0}",..
4df0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 6e in
4e00: 64 65 78 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 dex);....
4e10: 20 20 20 20 20 20 20 20 20 20 20 64 62 2e 41 64 db.Ad
4e20: 64 4f 62 6a 65 63 74 28 22 4f 72 64 65 72 73 22 dObject("Orders"
4e30: 2c 20 6e 65 77 4f 72 64 65 72 73 29 3b 0d 0a 0d , newOrders);...
4e40: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
4e50: 20 20 20 74 72 79 0d 0a 20 20 20 20 20 20 20 20 try..
4e60: 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 {..
4e70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
4e80: 20 20 20 64 62 2e 53 61 76 65 43 68 61 6e 67 65 db.SaveChange
4e90: 73 28 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 s();..
4ea0: 20 20 20 20 20 20 20 20 20 20 20 20 63 6f 75 6e coun
4eb0: 74 73 5b 30 5d 2b 2b 3b 0d 0a 0d 0a 20 20 20 20 ts[0]++;....
4ec0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
4ed0: 20 20 2f 2f 20 53 74 6f 72 65 47 65 6e 65 72 61 // StoreGenera
4ee0: 74 65 64 50 61 74 74 65 72 6e 3d 22 49 64 65 6e tedPattern="Iden
4ef0: 74 69 74 79 22 0d 0a 20 20 20 20 20 20 20 20 20 tity"..
4f00: 20 20 20 20 20 20 20 20 20 20 20 20 20 6f 72 64 ord
4f10: 65 72 49 64 73 5b 69 6e 64 65 78 5d 20 3d 20 6e erIds[index] = n
4f20: 65 77 4f 72 64 65 72 73 2e 4f 72 64 65 72 49 44 ewOrders.OrderID
4f30: 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ;....
4f40: 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 53 74 // St
4f50: 6f 72 65 47 65 6e 65 72 61 74 65 64 50 61 74 74 oreGeneratedPatt
4f60: 65 72 6e 3d 22 4e 6f 6e 65 22 0d 0a 20 20 20 20 ern="None"..
4f70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
4f80: 20 20 6e 65 77 4f 72 64 65 72 73 2e 53 68 69 70 newOrders.Ship
4f90: 41 64 64 72 65 73 73 20 3d 20 53 74 72 69 6e 67 Address = String
4fa0: 2e 46 6f 72 6d 61 74 28 0d 0a 20 20 20 20 20 20 .Format(..
4fb0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
4fc0: 20 20 20 20 22 4e 65 77 20 4f 72 64 65 72 20 53 "New Order S
4fd0: 68 69 70 20 41 64 64 72 65 73 73 20 23 7b 30 7d hip Address #{0}
4fe0: 22 2c 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 ",..
4ff0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 6f 72 or
5000: 64 65 72 49 64 73 5b 69 6e 64 65 78 5d 29 3b 0d derIds[index]);.
5010: 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ...
5020: 20 20 20 20 20 20 20 20 20 2f 2f 20 53 74 6f 72 // Stor
5030: 65 47 65 6e 65 72 61 74 65 64 50 61 74 74 65 72 eGeneratedPatter
5040: 6e 3d 22 43 6f 6d 70 75 74 65 64 22 0d 0a 20 20 n="Computed"..
5050: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5060: 20 20 20 20 6e 65 77 4f 72 64 65 72 73 2e 46 72 newOrders.Fr
5070: 65 69 67 68 74 20 3d 20 31 3b 0d 0a 0d 0a 20 20 eight = 1;....
5080: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5090: 20 20 20 20 64 62 2e 53 61 76 65 43 68 61 6e 67 db.SaveChang
50a0: 65 73 28 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 es();..
50b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 63 6f 75 cou
50c0: 6e 74 73 5b 31 5d 2b 2b 3b 0d 0a 20 20 20 20 20 nts[1]++;..
50d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a }..
50e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
50f0: 20 20 63 61 74 63 68 20 28 45 78 63 65 70 74 69 catch (Excepti
5100: 6f 6e 20 65 29 0d 0a 20 20 20 20 20 20 20 20 20 on e)..
5110: 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 {..
5120: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5130: 20 20 43 6f 6e 73 6f 6c 65 2e 57 72 69 74 65 4c Console.WriteL
5140: 69 6e 65 28 65 29 3b 0d 0a 20 20 20 20 20 20 20 ine(e);..
5150: 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 }..
5160: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5170: 66 69 6e 61 6c 6c 79 0d 0a 20 20 20 20 20 20 20 finally..
5180: 20 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 {..
5190: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
51a0: 20 20 20 20 64 62 2e 41 63 63 65 70 74 41 6c 6c db.AcceptAll
51b0: 43 68 61 6e 67 65 73 28 29 3b 0d 0a 20 20 20 20 Changes();..
51c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d }.
51d0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d . }
51e0: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 ....
51f0: 20 20 43 6f 6e 73 6f 6c 65 2e 57 72 69 74 65 4c Console.WriteL
5200: 69 6e 65 28 0d 0a 20 20 20 20 20 20 20 20 20 20 ine(..
5210: 20 20 20 20 20 20 20 20 22 69 6e 73 65 72 74 65 "inserte
5220: 64 20 7b 30 7d 20 75 70 64 61 74 65 64 20 7b 31 d {0} updated {1
5230: 7d 22 2c 20 63 6f 75 6e 74 73 5b 30 5d 2c 20 63 }", counts[0], c
5240: 6f 75 6e 74 73 5b 31 5d 29 3b 0d 0a 20 20 20 20 ounts[1]);..
5250: 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 }....
5260: 20 20 20 20 20 72 65 74 75 72 6e 20 30 3b 0d 0a return 0;..
5270: 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 }....
5280: 20 2f 2f 0d 0a 20 20 20 20 20 20 2f 2f 20 4e 4f //.. // NO
5290: 54 45 3a 20 55 73 65 64 20 74 6f 20 74 65 73 74 TE: Used to test
52a0: 20 74 68 65 20 42 69 6e 61 72 79 47 55 49 44 20 the BinaryGUID
52b0: 66 69 78 20 28 69 2e 65 2e 20 42 4c 4f 42 20 6c fix (i.e. BLOB l
52c0: 69 74 65 72 61 6c 20 66 6f 72 6d 61 74 74 69 6e iteral formattin
52d0: 67 0d 0a 20 20 20 20 20 20 2f 2f 20 20 20 20 20 g.. //
52e0: 20 20 6f 66 20 47 55 49 44 20 76 61 6c 75 65 73 of GUID values
52f0: 20 77 68 65 6e 20 74 68 65 20 42 69 6e 61 72 79 when the Binary
5300: 47 55 49 44 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 GUID connection
5310: 70 72 6f 70 65 72 74 79 20 68 61 73 20 62 65 65 property has bee
5320: 6e 0d 0a 20 20 20 20 20 20 2f 2f 20 20 20 20 20 n.. //
5330: 20 20 65 6e 61 62 6c 65 64 29 2e 0d 0a 20 20 20 enabled)...
5340: 20 20 20 2f 2f 0d 0a 20 20 20 20 20 20 70 72 69 //.. pri
5350: 76 61 74 65 20 73 74 61 74 69 63 20 69 6e 74 20 vate static int
5360: 42 69 6e 61 72 79 47 75 69 64 54 65 73 74 28 62 BinaryGuidTest(b
5370: 6f 6f 6c 20 62 69 6e 61 72 79 47 75 69 64 29 0d ool binaryGuid).
5380: 0a 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 . {..
5390: 20 20 20 20 45 6e 76 69 72 6f 6e 6d 65 6e 74 2e Environment.
53a0: 53 65 74 45 6e 76 69 72 6f 6e 6d 65 6e 74 56 61 SetEnvironmentVa
53b0: 72 69 61 62 6c 65 28 0d 0a 20 20 20 20 20 20 20 riable(..
53c0: 20 20 20 20 20 20 20 22 41 70 70 65 6e 64 4d 61 "AppendMa
53d0: 6e 69 66 65 73 74 54 6f 6b 65 6e 5f 53 51 4c 69 nifestToken_SQLi
53e0: 74 65 50 72 6f 76 69 64 65 72 4d 61 6e 69 66 65 teProviderManife
53f0: 73 74 22 2c 0d 0a 20 20 20 20 20 20 20 20 20 20 st",..
5400: 20 20 20 20 53 74 72 69 6e 67 2e 46 6f 72 6d 61 String.Forma
5410: 74 28 22 3b 42 69 6e 61 72 79 47 55 49 44 3d 7b t(";BinaryGUID={
5420: 30 7d 3b 22 2c 20 62 69 6e 61 72 79 47 75 69 64 0};", binaryGuid
5430: 29 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 ));....
5440: 20 75 73 69 6e 67 20 28 6e 6f 72 74 68 77 69 6e using (northwin
5450: 64 45 46 45 6e 74 69 74 69 65 73 20 64 62 20 3d dEFEntities db =
5460: 20 6e 65 77 20 6e 6f 72 74 68 77 69 6e 64 45 46 new northwindEF
5470: 45 6e 74 69 74 69 65 73 28 29 29 0d 0a 20 20 20 Entities())..
5480: 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 {..
5490: 20 20 20 20 20 20 20 20 73 74 72 69 6e 67 20 73 string s
54a0: 71 6c 20 3d 20 22 53 45 4c 45 43 54 20 56 41 4c ql = "SELECT VAL
54b0: 55 45 20 47 55 49 44 20 22 20 2b 0d 0a 20 20 20 UE GUID " +..
54c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 "
54d0: 27 32 64 33 64 32 64 33 64 2d 32 64 33 64 2d 32 '2d3d2d3d-2d3d-2
54e0: 64 33 64 2d 32 64 33 64 2d 32 64 33 64 32 64 33 d3d-2d3d-2d3d2d3
54f0: 64 32 64 33 64 27 20 22 20 2b 0d 0a 20 20 20 20 d2d3d' " +..
5500: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 46 "F
5510: 52 4f 4d 20 4f 72 64 65 72 73 20 41 53 20 6f 20 ROM Orders AS o
5520: 57 48 45 52 45 20 6f 2e 4f 72 64 65 72 49 44 20 WHERE o.OrderID
5530: 3d 20 31 30 32 34 38 3b 22 3b 0d 0a 0d 0a 20 20 = 10248;";....
5540: 20 20 20 20 20 20 20 20 20 20 20 20 4f 62 6a 65 Obje
5550: 63 74 51 75 65 72 79 3c 73 74 72 69 6e 67 3e 20 ctQuery<string>
5560: 71 75 65 72 79 20 3d 20 64 62 2e 43 72 65 61 74 query = db.Creat
5570: 65 51 75 65 72 79 3c 73 74 72 69 6e 67 3e 28 73 eQuery<string>(s
5580: 71 6c 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 ql);....
5590: 20 20 20 20 20 20 66 6f 72 65 61 63 68 20 28 73 foreach (s
55a0: 74 72 69 6e 67 20 73 20 69 6e 20 71 75 65 72 79 tring s in query
55b0: 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 )..
55c0: 20 20 20 20 20 43 6f 6e 73 6f 6c 65 2e 57 72 69 Console.Wri
55d0: 74 65 4c 69 6e 65 28 73 29 3b 0d 0a 20 20 20 20 teLine(s);..
55e0: 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 }....
55f0: 20 20 20 20 20 45 6e 76 69 72 6f 6e 6d 65 6e 74 Environment
5600: 2e 53 65 74 45 6e 76 69 72 6f 6e 6d 65 6e 74 56 .SetEnvironmentV
5610: 61 72 69 61 62 6c 65 28 0d 0a 20 20 20 20 20 20 ariable(..
5620: 20 20 20 20 20 20 20 20 22 41 70 70 65 6e 64 4d "AppendM
5630: 61 6e 69 66 65 73 74 54 6f 6b 65 6e 5f 53 51 4c anifestToken_SQL
5640: 69 74 65 50 72 6f 76 69 64 65 72 4d 61 6e 69 66 iteProviderManif
5650: 65 73 74 22 2c 0d 0a 20 20 20 20 20 20 20 20 20 est",..
5660: 20 20 20 20 20 6e 75 6c 6c 29 3b 0d 0a 0d 0a 20 null);....
5670: 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 return
5680: 30 3b 0d 0a 20 20 20 20 20 20 7d 0d 0a 0d 0a 23 0;.. }....#
5690: 69 66 20 4e 45 54 5f 34 30 20 7c 7c 20 4e 45 54 if NET_40 || NET
56a0: 5f 34 35 20 7c 7c 20 4e 45 54 5f 34 35 31 0d 0a _45 || NET_451..
56b0: 20 20 20 20 20 20 2f 2f 0d 0a 20 20 20 20 20 20 //..
56c0: 2f 2f 20 4e 4f 54 45 3a 20 55 73 65 64 20 74 6f // NOTE: Used to
56d0: 20 74 65 73 74 20 74 68 65 20 42 69 6e 61 72 79 test the Binary
56e0: 47 55 49 44 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 GUID connection
56f0: 73 74 72 69 6e 67 20 70 72 6f 70 65 72 74 79 20 string property
5700: 77 69 74 68 0d 0a 20 20 20 20 20 20 2f 2f 20 20 with.. //
5710: 20 20 20 20 20 74 68 65 20 43 6f 6e 74 61 69 6e the Contain
5720: 73 28 29 20 66 75 6e 63 74 69 6f 6e 20 28 74 69 s() function (ti
5730: 63 6b 65 74 20 5b 61 34 64 39 63 37 65 65 39 34 cket [a4d9c7ee94
5740: 5d 29 2e 20 20 57 65 20 63 61 6e 6e 6f 74 0d 0a ]). We cannot..
5750: 20 20 20 20 20 20 2f 2f 20 20 20 20 20 20 20 75 // u
5760: 73 65 20 74 68 65 20 43 6f 6e 74 61 69 6e 73 20 se the Contains
5770: 65 78 74 65 6e 73 69 6f 6e 20 6d 65 74 68 6f 64 extension method
5780: 20 77 69 74 68 69 6e 20 61 20 4c 49 4e 51 20 71 within a LINQ q
5790: 75 65 72 79 20 77 69 74 68 0d 0a 20 20 20 20 20 uery with..
57a0: 20 2f 2f 20 20 20 20 20 20 20 74 68 65 20 2e 4e // the .N
57b0: 45 54 20 46 72 61 6d 65 77 6f 72 6b 20 33 2e 35 ET Framework 3.5
57c0: 2e 0d 0a 20 20 20 20 20 20 2f 2f 0d 0a 20 20 20 ... //..
57d0: 20 20 20 70 72 69 76 61 74 65 20 73 74 61 74 69 private stati
57e0: 63 20 69 6e 74 20 42 69 6e 61 72 79 47 75 69 64 c int BinaryGuid
57f0: 54 65 73 74 32 28 62 6f 6f 6c 20 62 69 6e 61 72 Test2(bool binar
5800: 79 47 75 69 64 29 0d 0a 20 20 20 20 20 20 7b 0d yGuid).. {.
5810: 0a 20 20 20 20 20 20 20 20 20 20 45 6e 76 69 72 . Envir
5820: 6f 6e 6d 65 6e 74 2e 53 65 74 45 6e 76 69 72 6f onment.SetEnviro
5830: 6e 6d 65 6e 74 56 61 72 69 61 62 6c 65 28 0d 0a nmentVariable(..
5840: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 41 "A
5850: 70 70 65 6e 64 4d 61 6e 69 66 65 73 74 54 6f 6b ppendManifestTok
5860: 65 6e 5f 53 51 4c 69 74 65 50 72 6f 76 69 64 65 en_SQLiteProvide
5870: 72 4d 61 6e 69 66 65 73 74 22 2c 0d 0a 20 20 20 rManifest",..
5880: 20 20 20 20 20 20 20 20 20 20 20 53 74 72 69 6e Strin
5890: 67 2e 46 6f 72 6d 61 74 28 22 3b 42 69 6e 61 72 g.Format(";Binar
58a0: 79 47 55 49 44 3d 7b 30 7d 3b 22 2c 20 62 69 6e yGUID={0};", bin
58b0: 61 72 79 47 75 69 64 29 29 3b 0d 0a 0d 0a 20 20 aryGuid));....
58c0: 20 20 20 20 20 20 20 20 75 73 69 6e 67 20 28 6e using (n
58d0: 6f 72 74 68 77 69 6e 64 45 46 45 6e 74 69 74 69 orthwindEFEntiti
58e0: 65 73 20 64 62 20 3d 20 6e 65 77 20 6e 6f 72 74 es db = new nort
58f0: 68 77 69 6e 64 45 46 45 6e 74 69 74 69 65 73 28 hwindEFEntities(
5900: 29 29 0d 0a 20 20 20 20 20 20 20 20 20 20 7b 0d )).. {.
5910: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 47 . G
5920: 75 69 64 20 67 75 69 64 20 3d 20 6e 65 77 20 47 uid guid = new G
5930: 75 69 64 28 22 32 64 33 64 32 64 33 64 2d 32 64 uid("2d3d2d3d-2d
5940: 33 64 2d 32 64 33 64 2d 32 64 33 64 2d 32 64 33 3d-2d3d-2d3d-2d3
5950: 64 32 64 33 64 32 64 33 64 22 29 3b 0d 0a 20 20 d2d3d2d3d");..
5960: 20 20 20 20 20 20 20 20 20 20 20 20 47 75 69 64 Guid
5970: 5b 5d 20 67 75 69 64 73 20 3d 20 6e 65 77 20 47 [] guids = new G
5980: 75 69 64 5b 5d 20 7b 20 67 75 69 64 20 7d 3b 0d uid[] { guid };.
5990: 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ...
59a0: 20 62 6f 6f 6c 20 6f 6e 63 65 20 3d 20 66 61 6c bool once = fal
59b0: 73 65 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 se;..
59c0: 20 20 20 76 61 72 20 71 75 65 72 79 20 3d 20 66 var query = f
59d0: 72 6f 6d 20 74 20 69 6e 20 64 62 2e 54 65 72 72 rom t in db.Terr
59e0: 69 74 6f 72 69 65 73 0d 0a 20 20 20 20 20 20 20 itories..
59f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5a00: 20 20 20 77 68 65 72 65 20 67 75 69 64 73 2e 41 where guids.A
5a10: 73 51 75 65 72 79 61 62 6c 65 3c 47 75 69 64 3e sQueryable<Guid>
5a20: 28 29 2e 43 6f 6e 74 61 69 6e 73 3c 47 75 69 64 ().Contains<Guid
5a30: 3e 28 67 75 69 64 29 0d 0a 20 20 20 20 20 20 20 >(guid)..
5a40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5a50: 20 20 20 6f 72 64 65 72 62 79 20 74 2e 54 65 72 orderby t.Ter
5a60: 72 69 74 6f 72 79 49 44 0d 0a 20 20 20 20 20 20 ritoryID..
5a70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5a80: 20 20 20 20 73 65 6c 65 63 74 20 74 3b 0d 0a 0d select t;...
5a90: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 66 . f
5aa0: 6f 72 65 61 63 68 20 28 54 65 72 72 69 74 6f 72 oreach (Territor
5ab0: 69 65 73 20 74 20 69 6e 20 71 75 65 72 79 29 0d ies t in query).
5ac0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7b . {
5ad0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
5ae0: 20 20 20 20 69 66 20 28 6f 6e 63 65 29 0d 0a 20 if (once)..
5af0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5b00: 20 20 20 20 20 43 6f 6e 73 6f 6c 65 2e 57 72 69 Console.Wri
5b10: 74 65 28 27 20 27 29 3b 0d 0a 0d 0a 20 20 20 20 te(' ');....
5b20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 43 6f Co
5b30: 6e 73 6f 6c 65 2e 57 72 69 74 65 28 74 2e 54 65 nsole.Write(t.Te
5b40: 72 72 69 74 6f 72 79 49 44 29 3b 0d 0a 0d 0a 20 rritoryID);....
5b50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5b60: 20 6f 6e 63 65 20 3d 20 74 72 75 65 3b 0d 0a 20 once = true;..
5b70: 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a }..
5b80: 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 }....
5b90: 20 20 20 20 20 20 20 20 20 45 6e 76 69 72 6f 6e Environ
5ba0: 6d 65 6e 74 2e 53 65 74 45 6e 76 69 72 6f 6e 6d ment.SetEnvironm
5bb0: 65 6e 74 56 61 72 69 61 62 6c 65 28 0d 0a 20 20 entVariable(..
5bc0: 20 20 20 20 20 20 20 20 20 20 20 20 22 41 70 70 "App
5bd0: 65 6e 64 4d 61 6e 69 66 65 73 74 54 6f 6b 65 6e endManifestToken
5be0: 5f 53 51 4c 69 74 65 50 72 6f 76 69 64 65 72 4d _SQLiteProviderM
5bf0: 61 6e 69 66 65 73 74 22 2c 0d 0a 20 20 20 20 20 anifest",..
5c00: 20 20 20 20 20 20 20 20 20 6e 75 6c 6c 29 3b 0d null);.
5c10: 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 72 65 74 ... ret
5c20: 75 72 6e 20 30 3b 0d 0a 20 20 20 20 20 20 7d 0d urn 0;.. }.
5c30: 0a 23 65 6e 64 69 66 0d 0a 0d 0a 20 20 20 20 20 .#endif....
5c40: 20 70 72 69 76 61 74 65 20 73 74 61 74 69 63 20 private static
5c50: 69 6e 74 20 44 61 74 65 54 69 6d 65 54 65 73 74 int DateTimeTest
5c60: 28 29 0d 0a 20 20 20 20 20 20 7b 0d 0a 20 20 20 ().. {..
5c70: 20 20 20 20 20 20 20 75 73 69 6e 67 20 28 6e 6f using (no
5c80: 72 74 68 77 69 6e 64 45 46 45 6e 74 69 74 69 65 rthwindEFEntitie
5c90: 73 20 64 62 20 3d 20 6e 65 77 20 6e 6f 72 74 68 s db = new north
5ca0: 77 69 6e 64 45 46 45 6e 74 69 74 69 65 73 28 29 windEFEntities()
5cb0: 29 0d 0a 20 20 20 20 20 20 20 20 20 20 7b 0d 0a ).. {..
5cc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 44 61 Da
5cd0: 74 65 54 69 6d 65 20 64 61 74 65 54 69 6d 65 20 teTime dateTime
5ce0: 3d 20 6e 65 77 20 44 61 74 65 54 69 6d 65 28 31 = new DateTime(1
5cf0: 39 39 37 2c 20 31 2c 20 31 2c 20 30 2c 20 30 2c 997, 1, 1, 0, 0,
5d00: 20 30 2c 20 44 61 74 65 54 69 6d 65 4b 69 6e 64 0, DateTimeKind
5d10: 2e 4c 6f 63 61 6c 29 3b 0d 0a 20 20 20 20 20 20 .Local);..
5d20: 20 20 20 20 20 20 20 20 69 6e 74 20 63 31 20 3d int c1 =
5d30: 20 64 62 2e 4f 72 64 65 72 73 2e 57 68 65 72 65 db.Orders.Where
5d40: 28 69 20 3d 3e 20 69 2e 4f 72 64 65 72 44 61 74 (i => i.OrderDat
5d50: 65 20 3d 3d 20 6e 65 77 20 44 61 74 65 54 69 6d e == new DateTim
5d60: 65 28 31 39 39 37 2c 20 31 2c 20 31 2c 20 30 2c e(1997, 1, 1, 0,
5d70: 20 30 2c 20 30 2c 20 44 61 74 65 54 69 6d 65 4b 0, 0, DateTimeK
5d80: 69 6e 64 2e 4c 6f 63 61 6c 29 29 2e 43 6f 75 6e ind.Local)).Coun
5d90: 74 28 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 t();..
5da0: 20 20 20 20 69 6e 74 20 63 32 20 3d 20 64 62 2e int c2 = db.
5db0: 4f 72 64 65 72 73 2e 57 68 65 72 65 28 69 20 3d Orders.Where(i =
5dc0: 3e 20 69 2e 4f 72 64 65 72 44 61 74 65 20 3d 3d > i.OrderDate ==
5dd0: 20 64 61 74 65 54 69 6d 65 29 2e 43 6f 75 6e 74 dateTime).Count
5de0: 28 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 ();..
5df0: 20 20 20 72 65 74 75 72 6e 20 63 31 20 3d 3d 20 return c1 ==
5e00: 63 32 20 3f 20 30 20 3a 20 31 3b 0d 0a 20 20 20 c2 ? 0 : 1;..
5e10: 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 }..
5e20: 7d 0d 0a 0d 0a 20 20 20 20 20 20 70 72 69 76 61 }.... priva
5e30: 74 65 20 73 74 61 74 69 63 20 76 6f 69 64 20 44 te static void D
5e40: 61 74 65 54 69 6d 65 54 65 73 74 32 28 0d 0a 20 ateTimeTest2(..
5e50: 20 20 20 20 20 20 20 20 20 73 74 72 69 6e 67 20 string
5e60: 64 61 74 65 54 69 6d 65 46 6f 72 6d 61 74 0d 0a dateTimeFormat..
5e70: 20 20 20 20 20 20 20 20 20 20 29 0d 0a 20 20 20 )..
5e80: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 {..
5e90: 54 72 61 63 65 4c 69 73 74 65 6e 65 72 20 6c 69 TraceListener li
5ea0: 73 74 65 6e 65 72 20 3d 20 6e 65 77 20 43 6f 6e stener = new Con
5eb0: 73 6f 6c 65 54 72 61 63 65 4c 69 73 74 65 6e 65 soleTraceListene
5ec0: 72 28 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 r();....
5ed0: 20 20 54 72 61 63 65 2e 4c 69 73 74 65 6e 65 72 Trace.Listener
5ee0: 73 2e 41 64 64 28 6c 69 73 74 65 6e 65 72 29 3b s.Add(listener);
5ef0: 0d 0a 20 20 20 20 20 20 20 20 20 20 45 6e 76 69 .. Envi
5f00: 72 6f 6e 6d 65 6e 74 2e 53 65 74 45 6e 76 69 72 ronment.SetEnvir
5f10: 6f 6e 6d 65 6e 74 56 61 72 69 61 62 6c 65 28 22 onmentVariable("
5f20: 53 51 4c 69 74 65 5f 46 6f 72 63 65 4c 6f 67 50 SQLite_ForceLogP
5f30: 72 65 70 61 72 65 22 2c 20 22 31 22 29 3b 0d 0a repare", "1");..
5f40: 0d 0a 20 20 20 20 20 20 20 20 20 20 69 66 20 28 .. if (
5f50: 64 61 74 65 54 69 6d 65 46 6f 72 6d 61 74 20 21 dateTimeFormat !
5f60: 3d 20 6e 75 6c 6c 29 0d 0a 20 20 20 20 20 20 20 = null)..
5f70: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 {..
5f80: 20 20 20 20 45 6e 76 69 72 6f 6e 6d 65 6e 74 2e Environment.
5f90: 53 65 74 45 6e 76 69 72 6f 6e 6d 65 6e 74 56 61 SetEnvironmentVa
5fa0: 72 69 61 62 6c 65 28 0d 0a 20 20 20 20 20 20 20 riable(..
5fb0: 20 20 20 20 20 20 20 20 20 20 20 22 41 70 70 65 "Appe
5fc0: 6e 64 4d 61 6e 69 66 65 73 74 54 6f 6b 65 6e 5f ndManifestToken_
5fd0: 53 51 4c 69 74 65 50 72 6f 76 69 64 65 72 4d 61 SQLiteProviderMa
5fe0: 6e 69 66 65 73 74 22 2c 0d 0a 20 20 20 20 20 20 nifest",..
5ff0: 20 20 20 20 20 20 20 20 20 20 20 20 53 74 72 69 Stri
6000: 6e 67 2e 46 6f 72 6d 61 74 28 22 3b 44 61 74 65 ng.Format(";Date
6010: 54 69 6d 65 46 6f 72 6d 61 74 3d 7b 30 7d 3b 22 TimeFormat={0};"
6020: 2c 20 64 61 74 65 54 69 6d 65 46 6f 72 6d 61 74 , dateTimeFormat
6030: 29 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 7d ));.. }
6040: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 75 73 .... us
6050: 69 6e 67 20 28 6e 6f 72 74 68 77 69 6e 64 45 46 ing (northwindEF
6060: 45 6e 74 69 74 69 65 73 20 64 62 20 3d 20 6e 65 Entities db = ne
6070: 77 20 6e 6f 72 74 68 77 69 6e 64 45 46 45 6e 74 w northwindEFEnt
6080: 69 74 69 65 73 28 29 29 0d 0a 20 20 20 20 20 20 ities())..
6090: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 {..
60a0: 20 20 20 20 20 64 62 2e 4f 72 64 65 72 73 2e 57 db.Orders.W
60b0: 68 65 72 65 28 69 20 3d 3e 20 69 2e 4f 72 64 65 here(i => i.Orde
60c0: 72 44 61 74 65 20 3c 0d 0a 20 20 20 20 20 20 20 rDate <..
60d0: 20 20 20 20 20 20 20 20 20 20 20 6e 65 77 20 44 new D
60e0: 61 74 65 54 69 6d 65 28 31 39 39 37 2c 20 31 2c ateTime(1997, 1,
60f0: 20 31 2c 20 30 2c 20 30 2c 20 30 2c 20 44 61 74 1, 0, 0, 0, Dat
6100: 65 54 69 6d 65 4b 69 6e 64 2e 4c 6f 63 61 6c 29 eTimeKind.Local)
6110: 29 2e 43 6f 75 6e 74 28 29 3b 0d 0a 20 20 20 20 ).Count();..
6120: 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 }....
6130: 20 20 20 20 20 69 66 20 28 64 61 74 65 54 69 6d if (dateTim
6140: 65 46 6f 72 6d 61 74 20 21 3d 20 6e 75 6c 6c 29 eFormat != null)
6150: 0d 0a 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 .. {..
6160: 20 20 20 20 20 20 20 20 20 20 20 20 20 45 6e 76 Env
6170: 69 72 6f 6e 6d 65 6e 74 2e 53 65 74 45 6e 76 69 ironment.SetEnvi
6180: 72 6f 6e 6d 65 6e 74 56 61 72 69 61 62 6c 65 28 ronmentVariable(
6190: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
61a0: 20 20 20 20 22 41 70 70 65 6e 64 4d 61 6e 69 66 "AppendManif
61b0: 65 73 74 54 6f 6b 65 6e 5f 53 51 4c 69 74 65 50 estToken_SQLiteP
61c0: 72 6f 76 69 64 65 72 4d 61 6e 69 66 65 73 74 22 roviderManifest"
61d0: 2c 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ,..
61e0: 20 20 20 20 20 6e 75 6c 6c 29 3b 0d 0a 20 20 20 null);..
61f0: 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 }....
6200: 20 20 20 20 20 20 45 6e 76 69 72 6f 6e 6d 65 6e Environmen
6210: 74 2e 53 65 74 45 6e 76 69 72 6f 6e 6d 65 6e 74 t.SetEnvironment
6220: 56 61 72 69 61 62 6c 65 28 22 53 51 4c 69 74 65 Variable("SQLite
6230: 5f 46 6f 72 63 65 4c 6f 67 50 72 65 70 61 72 65 _ForceLogPrepare
6240: 22 2c 20 6e 75 6c 6c 29 3b 0d 0a 20 20 20 20 20 ", null);..
6250: 20 20 20 20 20 54 72 61 63 65 2e 4c 69 73 74 65 Trace.Liste
6260: 6e 65 72 73 2e 52 65 6d 6f 76 65 28 6c 69 73 74 ners.Remove(list
6270: 65 6e 65 72 29 3b 0d 0a 20 20 20 20 20 20 7d 0d ener);.. }.
6280: 0a 0d 0a 20 20 20 20 70 72 69 76 61 74 65 20 73 ... private s
6290: 74 61 74 69 63 20 69 6e 74 20 4f 6c 64 54 65 73 tatic int OldTes
62a0: 74 73 28 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 ts().. {..
62b0: 20 20 20 75 73 69 6e 67 20 28 6e 6f 72 74 68 77 using (northw
62c0: 69 6e 64 45 46 45 6e 74 69 74 69 65 73 20 64 62 indEFEntities db
62d0: 20 3d 20 6e 65 77 20 6e 6f 72 74 68 77 69 6e 64 = new northwind
62e0: 45 46 45 6e 74 69 74 69 65 73 28 29 29 0d 0a 20 EFEntities())..
62f0: 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 {..
6300: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 73 74 72 {.. str
6310: 69 6e 67 20 65 6e 74 69 74 79 53 51 4c 20 3d 20 ing entitySQL =
6320: 22 53 45 4c 45 43 54 20 56 41 4c 55 45 20 6f 20 "SELECT VALUE o
6330: 46 52 4f 4d 20 4f 72 64 65 72 73 20 41 53 20 6f FROM Orders AS o
6340: 20 57 48 45 52 45 20 53 51 4c 69 74 65 2e 44 61 WHERE SQLite.Da
6350: 74 65 50 61 72 74 28 27 79 79 79 79 27 2c 20 6f tePart('yyyy', o
6360: 2e 4f 72 64 65 72 44 61 74 65 29 20 3d 20 31 39 .OrderDate) = 19
6370: 39 37 20 4f 52 44 45 52 20 42 59 20 6f 2e 4f 72 97 ORDER BY o.Or
6380: 64 65 72 49 44 3b 22 3b 0d 0a 20 20 20 20 20 20 derID;";..
6390: 20 20 20 20 4f 62 6a 65 63 74 51 75 65 72 79 3c ObjectQuery<
63a0: 4f 72 64 65 72 73 3e 20 71 75 65 72 79 20 3d 20 Orders> query =
63b0: 64 62 2e 43 72 65 61 74 65 51 75 65 72 79 3c 4f db.CreateQuery<O
63c0: 72 64 65 72 73 3e 28 65 6e 74 69 74 79 53 51 4c rders>(entitySQL
63d0: 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 );....
63e0: 66 6f 72 65 61 63 68 20 28 4f 72 64 65 72 73 20 foreach (Orders
63f0: 6f 20 69 6e 20 71 75 65 72 79 29 0d 0a 20 20 20 o in query)..
6400: 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 {..
6410: 20 20 20 20 20 20 43 6f 6e 73 6f 6c 65 2e 57 72 Console.Wr
6420: 69 74 65 4c 69 6e 65 28 6f 2e 53 68 69 70 50 6f iteLine(o.ShipPo
6430: 73 74 61 6c 43 6f 64 65 29 3b 0d 0a 20 20 20 20 stalCode);..
6440: 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 }..
6450: 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 20 20 7b 0d }.... {.
6460: 0a 20 20 20 20 20 20 20 20 20 20 76 61 72 20 71 . var q
6470: 75 65 72 79 20 3d 20 66 72 6f 6d 20 63 20 69 6e uery = from c in
6480: 20 64 62 2e 43 75 73 74 6f 6d 65 72 73 0d 0a 20 db.Customers..
6490: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
64a0: 20 20 20 20 20 77 68 65 72 65 20 63 2e 43 69 74 where c.Cit
64b0: 79 20 3d 3d 20 22 4c 6f 6e 64 6f 6e 22 0d 0a 20 y == "London"..
64c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
64d0: 20 20 20 20 20 6f 72 64 65 72 62 79 20 63 2e 43 orderby c.C
64e0: 6f 6d 70 61 6e 79 4e 61 6d 65 0d 0a 20 20 20 20 ompanyName..
64f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
6500: 20 20 73 65 6c 65 63 74 20 63 3b 0d 0a 0d 0a 20 select c;....
6510: 20 20 20 20 20 20 20 20 20 69 6e 74 20 63 63 20 int cc
6520: 3d 20 71 75 65 72 79 2e 43 6f 75 6e 74 28 29 3b = query.Count();
6530: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 66 6f .... fo
6540: 72 65 61 63 68 20 28 43 75 73 74 6f 6d 65 72 73 reach (Customers
6550: 20 63 20 69 6e 20 71 75 65 72 79 29 0d 0a 20 20 c in query)..
6560: 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 {..
6570: 20 20 20 20 20 20 20 43 6f 6e 73 6f 6c 65 2e 57 Console.W
6580: 72 69 74 65 4c 69 6e 65 28 63 2e 43 6f 6d 70 61 riteLine(c.Compa
6590: 6e 79 4e 61 6d 65 29 3b 0d 0a 20 20 20 20 20 20 nyName);..
65a0: 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 7d }.. }
65b0: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 7b 0d 0a 20 .... {..
65c0: 20 20 20 20 20 20 20 20 20 73 74 72 69 6e 67 20 string
65d0: 73 63 69 74 79 20 3d 20 22 4c 6f 6e 64 6f 6e 22 scity = "London"
65e0: 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 43 75 73 ;.. Cus
65f0: 74 6f 6d 65 72 73 20 63 20 3d 20 64 62 2e 43 75 tomers c = db.Cu
6600: 73 74 6f 6d 65 72 73 2e 46 69 72 73 74 4f 72 44 stomers.FirstOrD
6610: 65 66 61 75 6c 74 28 63 64 20 3d 3e 20 63 64 2e efault(cd => cd.
6620: 43 69 74 79 20 3d 3d 20 73 63 69 74 79 29 3b 0d City == scity);.
6630: 0a 20 20 20 20 20 20 20 20 20 20 43 6f 6e 73 6f . Conso
6640: 6c 65 2e 57 72 69 74 65 4c 69 6e 65 28 63 2e 43 le.WriteLine(c.C
6650: 6f 6d 70 61 6e 79 4e 61 6d 65 29 3b 0d 0a 20 20 ompanyName);..
6660: 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 }....
6670: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 {..
6680: 44 61 74 65 54 69 6d 65 20 64 74 20 3d 20 6e 65 DateTime dt = ne
6690: 77 20 44 61 74 65 54 69 6d 65 28 31 39 39 37 2c w DateTime(1997,
66a0: 20 31 2c 20 31 29 3b 0d 0a 20 20 20 20 20 20 20 1, 1);..
66b0: 20 20 20 76 61 72 20 71 75 65 72 79 20 3d 20 66 var query = f
66c0: 72 6f 6d 20 6f 72 64 65 72 20 69 6e 20 64 62 2e rom order in db.
66d0: 4f 72 64 65 72 73 0d 0a 20 20 20 20 20 20 20 20 Orders..
66e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 77 68 wh
66f0: 65 72 65 20 6f 72 64 65 72 2e 4f 72 64 65 72 44 ere order.OrderD
6700: 61 74 65 20 3c 20 64 74 0d 0a 20 20 20 20 20 20 ate < dt..
6710: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
6720: 6f 72 64 65 72 62 79 20 6f 72 64 65 72 2e 4f 72 orderby order.Or
6730: 64 65 72 49 44 0d 0a 20 20 20 20 20 20 20 20 20 derID..
6740: 20 20 20 20 20 20 20 20 20 20 20 20 20 73 65 6c sel
6750: 65 63 74 20 6f 72 64 65 72 3b 0d 0a 0d 0a 20 20 ect order;....
6760: 20 20 20 20 20 20 20 20 66 6f 72 65 61 63 68 20 foreach
6770: 28 4f 72 64 65 72 73 20 6f 20 69 6e 20 71 75 65 (Orders o in que
6780: 72 79 29 0d 0a 20 20 20 20 20 20 20 20 20 20 7b ry).. {
6790: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 43 6f .. Co
67a0: 6e 73 6f 6c 65 2e 57 72 69 74 65 4c 69 6e 65 28 nsole.WriteLine(
67b0: 6f 2e 4f 72 64 65 72 44 61 74 65 2e 54 6f 53 74 o.OrderDate.ToSt
67c0: 72 69 6e 67 28 29 29 3b 0d 0a 20 20 20 20 20 20 ring());..
67d0: 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 7d }.. }
67e0: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 7b 0d 0a 20 .... {..
67f0: 20 20 20 20 20 20 20 20 20 43 61 74 65 67 6f 72 Categor
6800: 69 65 73 20 63 20 3d 20 6e 65 77 20 43 61 74 65 ies c = new Cate
6810: 67 6f 72 69 65 73 28 29 3b 0d 0a 20 20 20 20 20 gories();..
6820: 20 20 20 20 20 63 2e 43 61 74 65 67 6f 72 79 4e c.CategoryN
6830: 61 6d 65 20 3d 20 22 54 65 73 74 20 43 61 74 65 ame = "Test Cate
6840: 67 6f 72 79 22 3b 0d 0a 20 20 20 20 20 20 20 20 gory";..
6850: 20 20 63 2e 44 65 73 63 72 69 70 74 69 6f 6e 20 c.Description
6860: 3d 20 22 4d 79 20 44 65 73 63 72 69 70 74 69 6f = "My Descriptio
6870: 6e 22 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 64 n";.. d
6880: 62 2e 41 64 64 54 6f 43 61 74 65 67 6f 72 69 65 b.AddToCategorie
6890: 73 28 63 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 s(c);..
68a0: 20 64 62 2e 53 61 76 65 43 68 61 6e 67 65 73 28 db.SaveChanges(
68b0: 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 );....
68c0: 43 6f 6e 73 6f 6c 65 2e 57 72 69 74 65 4c 69 6e Console.WriteLin
68d0: 65 28 63 2e 43 61 74 65 67 6f 72 79 49 44 29 3b e(c.CategoryID);
68e0: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 63 2e .... c.
68f0: 44 65 73 63 72 69 70 74 69 6f 6e 20 3d 20 22 4d Description = "M
6900: 79 20 6d 6f 64 69 66 69 65 64 20 64 65 73 63 72 y modified descr
6910: 69 70 74 69 6f 6e 22 3b 0d 0a 20 20 20 20 20 20 iption";..
6920: 20 20 20 20 64 62 2e 53 61 76 65 43 68 61 6e 67 db.SaveChang
6930: 65 73 28 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 es();....
6940: 20 20 20 64 62 2e 44 65 6c 65 74 65 4f 62 6a 65 db.DeleteObje
6950: 63 74 28 63 29 3b 0d 0a 20 20 20 20 20 20 20 20 ct(c);..
6960: 20 20 64 62 2e 53 61 76 65 43 68 61 6e 67 65 73 db.SaveChanges
6970: 28 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a ();.. }..
6980: 0d 0a 20 20 20 20 20 20 20 20 7b 0d 0a 20 20 20 .. {..
6990: 20 20 20 20 20 20 20 43 75 73 74 6f 6d 65 72 73 Customers
69a0: 20 63 75 73 74 20 3d 20 6e 65 77 20 43 75 73 74 cust = new Cust
69b0: 6f 6d 65 72 73 28 29 3b 0d 0a 20 20 20 20 20 20 omers();..
69c0: 20 20 20 20 63 75 73 74 2e 43 75 73 74 6f 6d 65 cust.Custome
69d0: 72 49 44 20 3d 20 22 4d 54 4d 54 4d 22 3b 0d 0a rID = "MTMTM";..
69e0: 20 20 20 20 20 20 20 20 20 20 63 75 73 74 2e 43 cust.C
69f0: 6f 6e 74 61 63 74 4e 61 6d 65 20 3d 20 22 4d 79 ontactName = "My
6a00: 20 4e 61 6d 65 22 3b 0d 0a 20 20 20 20 20 20 20 Name";..
6a10: 20 20 20 63 75 73 74 2e 43 6f 6d 70 61 6e 79 4e cust.CompanyN
6a20: 61 6d 65 20 3d 20 22 53 51 4c 69 74 65 20 43 6f ame = "SQLite Co
6a30: 6d 70 61 6e 79 22 3b 0d 0a 20 20 20 20 20 20 20 mpany";..
6a40: 20 20 20 63 75 73 74 2e 43 6f 75 6e 74 72 79 20 cust.Country
6a50: 3d 20 22 4e 65 74 68 65 72 6c 61 6e 64 73 22 3b = "Netherlands";
6a60: 0d 0a 20 20 20 20 20 20 20 20 20 20 63 75 73 74 .. cust
6a70: 2e 43 69 74 79 20 3d 20 22 41 6d 73 74 65 72 64 .City = "Amsterd
6a80: 61 6d 22 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 am";..
6a90: 63 75 73 74 2e 50 68 6f 6e 65 20 3d 20 22 30 31 cust.Phone = "01
6aa0: 32 33 34 35 36 37 37 22 3b 0d 0a 20 20 20 20 20 2345677";..
6ab0: 20 20 20 20 20 64 62 2e 41 64 64 54 6f 43 75 73 db.AddToCus
6ac0: 74 6f 6d 65 72 73 28 63 75 73 74 29 3b 0d 0a 20 tomers(cust);..
6ad0: 20 20 20 20 20 20 20 20 20 64 62 2e 53 61 76 65 db.Save
6ae0: 43 68 61 6e 67 65 73 28 29 3b 0d 0a 0d 0a 20 20 Changes();....
6af0: 20 20 20 20 20 20 20 20 64 62 2e 44 65 6c 65 74 db.Delet
6b00: 65 4f 62 6a 65 63 74 28 63 75 73 74 29 3b 0d 0a eObject(cust);..
6b10: 20 20 20 20 20 20 20 20 20 20 64 62 2e 53 61 76 db.Sav
6b20: 65 43 68 61 6e 67 65 73 28 29 3b 0d 0a 20 20 20 eChanges();..
6b30: 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 }....
6b40: 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 76 {.. v
6b50: 61 72 20 71 75 65 72 79 20 3d 20 64 62 2e 43 75 ar query = db.Cu
6b60: 73 74 6f 6d 65 72 73 2e 57 68 65 72 65 28 63 75 stomers.Where(cu
6b70: 73 74 20 3d 3e 20 63 75 73 74 2e 43 6f 75 6e 74 st => cust.Count
6b80: 72 79 20 3d 3d 20 22 44 65 6e 6d 61 72 6b 22 29 ry == "Denmark")
6b90: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
6ba0: 20 20 20 20 20 20 20 20 20 20 20 20 2e 53 65 6c .Sel
6bb0: 65 63 74 4d 61 6e 79 28 63 75 73 74 20 3d 3e 20 ectMany(cust =>
6bc0: 63 75 73 74 2e 4f 72 64 65 72 73 2e 57 68 65 72 cust.Orders.Wher
6bd0: 65 28 6f 20 3d 3e 20 6f 2e 46 72 65 69 67 68 74 e(o => o.Freight
6be0: 20 3e 20 35 29 29 0d 0a 20 20 20 20 20 20 20 20 > 5))..
6bf0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
6c00: 20 20 2e 4f 72 64 65 72 42 79 28 6f 20 3d 3e 20 .OrderBy(o =>
6c10: 6f 2e 43 75 73 74 6f 6d 65 72 73 2e 43 75 73 74 o.Customers.Cust
6c20: 6f 6d 65 72 49 44 29 3b 0d 0a 0d 0a 20 20 20 20 omerID);....
6c30: 20 20 20 20 20 20 66 6f 72 65 61 63 68 20 28 4f foreach (O
6c40: 72 64 65 72 73 20 63 20 69 6e 20 71 75 65 72 79 rders c in query
6c50: 29 0d 0a 20 20 20 20 20 20 20 20 20 20 7b 0d 0a ).. {..
6c60: 20 20 20 20 20 20 20 20 20 20 20 20 43 6f 6e 73 Cons
6c70: 6f 6c 65 2e 57 72 69 74 65 4c 69 6e 65 28 63 2e ole.WriteLine(c.
6c80: 46 72 65 69 67 68 74 29 3b 0d 0a 20 20 20 20 20 Freight);..
6c90: 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 }..
6ca0: 7d 0d 0a 0d 0a 20 20 20 20 20 20 20 20 7b 0d 0a }.... {..
6cb0: 20 20 20 20 20 20 20 20 20 20 76 61 72 20 71 75 var qu
6cc0: 65 72 79 20 3d 20 66 72 6f 6d 20 63 20 69 6e 20 ery = from c in
6cd0: 64 62 2e 43 75 73 74 6f 6d 65 72 73 0d 0a 20 20 db.Customers..
6ce0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
6cf0: 20 20 20 20 77 68 65 72 65 20 63 2e 4f 72 64 65 where c.Orde
6d00: 72 73 2e 41 6e 79 28 6f 20 3d 3e 20 6f 2e 4f 72 rs.Any(o => o.Or
6d10: 64 65 72 44 61 74 65 2e 48 61 73 56 61 6c 75 65 derDate.HasValue
6d20: 20 3d 3d 20 74 72 75 65 20 26 26 20 6f 2e 4f 72 == true && o.Or
6d30: 64 65 72 44 61 74 65 2e 56 61 6c 75 65 2e 59 65 derDate.Value.Ye
6d40: 61 72 20 3d 3d 20 31 39 39 37 29 0d 0a 20 20 20 ar == 1997)..
6d50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
6d60: 20 20 20 6f 72 64 65 72 62 79 20 63 2e 43 75 73 orderby c.Cus
6d70: 74 6f 6d 65 72 49 44 0d 0a 20 20 20 20 20 20 20 tomerID..
6d80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 73 s
6d90: 65 6c 65 63 74 20 63 3b 0d 0a 0d 0a 20 20 20 20 elect c;....
6da0: 20 20 20 20 20 20 66 6f 72 65 61 63 68 20 28 43 foreach (C
6db0: 75 73 74 6f 6d 65 72 73 20 63 20 69 6e 20 71 75 ustomers c in qu
6dc0: 65 72 79 29 0d 0a 20 20 20 20 20 20 20 20 20 20 ery)..
6dd0: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 43 {.. C
6de0: 6f 6e 73 6f 6c 65 2e 57 72 69 74 65 4c 69 6e 65 onsole.WriteLine
6df0: 28 63 2e 43 6f 6d 70 61 6e 79 4e 61 6d 65 29 3b (c.CompanyName);
6e00: 0d 0a 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 .. }..
6e10: 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 }....
6e20: 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 {..
6e30: 20 73 74 72 69 6e 67 20 65 6e 74 69 74 79 53 51 string entitySQ
6e40: 4c 20 3d 20 22 53 45 4c 45 43 54 20 56 41 4c 55 L = "SELECT VALU
6e50: 45 20 6f 20 46 52 4f 4d 20 4f 72 64 65 72 73 20 E o FROM Orders
6e60: 41 53 20 6f 20 57 48 45 52 45 20 6f 2e 43 75 73 AS o WHERE o.Cus
6e70: 74 6f 6d 65 72 73 2e 43 6f 75 6e 74 72 79 20 3c tomers.Country <
6e80: 3e 20 27 55 4b 27 20 41 4e 44 20 6f 2e 43 75 73 > 'UK' AND o.Cus
6e90: 74 6f 6d 65 72 73 2e 43 6f 75 6e 74 72 79 20 3c tomers.Country <
6ea0: 3e 20 27 4d 65 78 69 63 6f 27 20 41 4e 44 20 59 > 'Mexico' AND Y
6eb0: 65 61 72 28 6f 2e 4f 72 64 65 72 44 61 74 65 29 ear(o.OrderDate)
6ec0: 20 3d 20 31 39 39 37 20 4f 52 44 45 52 20 42 59 = 1997 ORDER BY
6ed0: 20 6f 2e 4f 72 64 65 72 49 44 3b 22 3b 0d 0a 20 o.OrderID;";..
6ee0: 20 20 20 20 20 20 20 20 20 4f 62 6a 65 63 74 51 ObjectQ
6ef0: 75 65 72 79 3c 4f 72 64 65 72 73 3e 20 71 75 65 uery<Orders> que
6f00: 72 79 20 3d 20 64 62 2e 43 72 65 61 74 65 51 75 ry = db.CreateQu
6f10: 65 72 79 3c 4f 72 64 65 72 73 3e 28 65 6e 74 69 ery<Orders>(enti
6f20: 74 79 53 51 4c 29 3b 0d 0a 0d 0a 20 20 20 20 20 tySQL);....
6f30: 20 20 20 20 20 66 6f 72 65 61 63 68 20 28 4f 72 foreach (Or
6f40: 64 65 72 73 20 6f 20 69 6e 20 71 75 65 72 79 29 ders o in query)
6f50: 0d 0a 20 20 20 20 20 20 20 20 20 20 7b 0d 0a 20 .. {..
6f60: 20 20 20 20 20 20 20 20 20 20 20 43 6f 6e 73 6f Conso
6f70: 6c 65 2e 57 72 69 74 65 4c 69 6e 65 28 6f 2e 53 le.WriteLine(o.S
6f80: 68 69 70 50 6f 73 74 61 6c 43 6f 64 65 29 3b 0d hipPostalCode);.
6f90: 0a 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 . }..
6fa0: 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 }....
6fb0: 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 {..
6fc0: 73 74 72 69 6e 67 20 65 6e 74 69 74 79 53 51 4c string entitySQL
6fd0: 20 3d 20 22 53 45 4c 45 43 54 20 56 41 4c 55 45 = "SELECT VALUE
6fe0: 20 6f 20 46 52 4f 4d 20 4f 72 64 65 72 73 20 41 o FROM Orders A
6ff0: 53 20 6f 20 57 48 45 52 45 20 4e 65 77 47 75 69 S o WHERE NewGui
7000: 64 28 29 20 3c 3e 20 4e 65 77 47 75 69 64 28 29 d() <> NewGuid()
7010: 20 4f 52 44 45 52 20 42 59 20 6f 2e 4f 72 64 65 ORDER BY o.Orde
7020: 72 49 44 3b 22 3b 0d 0a 20 20 20 20 20 20 20 20 rID;";..
7030: 20 20 4f 62 6a 65 63 74 51 75 65 72 79 3c 4f 72 ObjectQuery<Or
7040: 64 65 72 73 3e 20 71 75 65 72 79 20 3d 20 64 62 ders> query = db
7050: 2e 43 72 65 61 74 65 51 75 65 72 79 3c 4f 72 64 .CreateQuery<Ord
7060: 65 72 73 3e 28 65 6e 74 69 74 79 53 51 4c 29 3b ers>(entitySQL);
7070: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20 66 6f .... fo
7080: 72 65 61 63 68 20 28 4f 72 64 65 72 73 20 6f 20 reach (Orders o
7090: 69 6e 20 71 75 65 72 79 29 0d 0a 20 20 20 20 20 in query)..
70a0: 20 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 20 {..
70b0: 20 20 20 20 43 6f 6e 73 6f 6c 65 2e 57 72 69 74 Console.Writ
70c0: 65 4c 69 6e 65 28 6f 2e 53 68 69 70 50 6f 73 74 eLine(o.ShipPost
70d0: 61 6c 43 6f 64 65 29 3b 0d 0a 20 20 20 20 20 20 alCode);..
70e0: 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 7d }.. }
70f0: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 2f 2f 20 54 .... // T
7100: 68 69 73 20 71 75 65 72 79 20 72 65 71 75 69 72 his query requir
7110: 65 73 20 53 51 4c 69 74 65 20 33 2e 36 2e 32 20 es SQLite 3.6.2
7120: 74 6f 20 66 75 6e 63 74 69 6f 6e 20 63 6f 72 72 to function corr
7130: 65 63 74 6c 79 0d 0a 20 20 20 20 20 20 20 20 7b ectly.. {
7140: 0d 0a 20 20 20 20 20 20 20 20 20 20 76 61 72 20 .. var
7150: 71 75 65 72 79 20 3d 20 66 72 6f 6d 20 70 20 69 query = from p i
7160: 6e 20 64 62 2e 50 72 6f 64 75 63 74 73 0d 0a 20 n db.Products..
7170: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
7180: 20 20 20 20 20 77 68 65 72 65 20 70 2e 4f 72 64 where p.Ord
7190: 65 72 44 65 74 61 69 6c 73 2e 43 6f 75 6e 74 28 erDetails.Count(
71a0: 6f 64 20 3d 3e 20 6f 64 2e 4f 72 64 65 72 73 2e od => od.Orders.
71b0: 43 75 73 74 6f 6d 65 72 73 2e 43 6f 75 6e 74 72 Customers.Countr
71c0: 79 20 3d 3d 20 70 2e 53 75 70 70 6c 69 65 72 73 y == p.Suppliers
71d0: 2e 43 6f 75 6e 74 72 79 29 20 3e 20 32 0d 0a 20 .Country) > 2..
71e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
71f0: 20 20 20 20 20 6f 72 64 65 72 62 79 20 70 2e 50 orderby p.P
7200: 72 6f 64 75 63 74 49 44 0d 0a 20 20 20 20 20 20 roductID..
7210: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
7220: 73 65 6c 65 63 74 20 70 3b 0d 0a 0d 0a 20 20 20 select p;....
7230: 20 20 20 20 20 20 20 66 6f 72 65 61 63 68 20 28 foreach (
7240: 50 72 6f 64 75 63 74 73 20 70 20 69 6e 20 71 75 Products p in qu
7250: 65 72 79 29 0d 0a 20 20 20 20 20 20 20 20 20 20 ery)..
7260: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 43 {.. C
7270: 6f 6e 73 6f 6c 65 2e 57 72 69 74 65 4c 69 6e 65 onsole.WriteLine
7280: 28 70 2e 50 72 6f 64 75 63 74 4e 61 6d 65 29 3b (p.ProductName);
7290: 0d 0a 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 .. }..
72a0: 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 }..
72b0: 7d 0d 0a 0d 0a 20 20 20 20 20 20 2f 2f 0d 0a 20 }.... //..
72c0: 20 20 20 20 20 2f 2f 20 4e 4f 54 45 3a 20 28 4a // NOTE: (J
72d0: 4a 4d 29 20 52 65 6d 6f 76 65 64 20 6f 6e 20 32 JM) Removed on 2
72e0: 30 31 31 2f 30 37 2f 30 36 2c 20 6d 61 6b 65 73 011/07/06, makes
72f0: 20 69 74 20 68 61 72 64 65 72 20 74 6f 20 72 75 it harder to ru
7300: 6e 20 74 68 69 73 20 45 58 45 20 76 69 61 0d 0a n this EXE via..
7310: 20 20 20 20 20 20 2f 2f 20 20 20 20 20 20 20 74 // t
7320: 68 65 20 6e 65 77 20 75 6e 69 74 20 74 65 73 74 he new unit test
7330: 20 73 75 69 74 65 2e 0d 0a 20 20 20 20 20 20 2f suite... /
7340: 2f 0d 0a 20 20 20 20 20 20 2f 2f 20 43 6f 6e 73 /.. // Cons
7350: 6f 6c 65 2e 52 65 61 64 4b 65 79 28 29 3b 0d 0a ole.ReadKey();..
7360: 0d 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 30 .. return 0
7370: 3b 0d 0a 20 20 20 20 7d 0d 0a 20 20 7d 0d 0a 7d ;.. }.. }..}
7380: 0d 0a ..