├── .gitignore ├── .gitmodules ├── AzureCosmosDbDriver.sln ├── AzureDocumentDbDriver ├── AzureCosmosDbDriver.csproj ├── Common │ ├── DriverHelper.cs │ ├── Properties.cs │ └── SchemaBuilder.cs ├── Connection.png ├── DevDeploy.bat ├── Dynamic │ ├── ConnectionDialog.xaml │ ├── ConnectionDialog.xaml.cs │ └── DocumentDbDynamicDriver.cs ├── FailedConnection.png ├── Properties │ └── AssemblyInfo.cs ├── ReleaseDeploy.ps1 ├── Static │ ├── ConnectionDialog.xaml │ ├── ConnectionDialog.xaml.cs │ └── DocumentDbStaticDriver.cs ├── app.config ├── header.xml └── packages.config ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | #Key file 16 | *.pfx 17 | 18 | # Build results 19 | [Dd]ebug/ 20 | [Dd]ebugPublic/ 21 | [Rr]elease/ 22 | [Rr]eleases/ 23 | x64/ 24 | x86/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # .NET Core 49 | project.lock.json 50 | project.fragment.lock.json 51 | artifacts/ 52 | **/Properties/launchSettings.json 53 | 54 | *_i.c 55 | *_p.c 56 | *_i.h 57 | *.ilk 58 | *.meta 59 | *.obj 60 | *.pch 61 | *.pdb 62 | *.pgc 63 | *.pgd 64 | *.rsp 65 | *.sbr 66 | *.tlb 67 | *.tli 68 | *.tlh 69 | *.tmp 70 | *.tmp_proj 71 | *.log 72 | *.vspscc 73 | *.vssscc 74 | .builds 75 | *.pidb 76 | *.svclog 77 | *.scc 78 | 79 | # Chutzpah Test files 80 | _Chutzpah* 81 | 82 | # Visual C++ cache files 83 | ipch/ 84 | *.aps 85 | *.ncb 86 | *.opendb 87 | *.opensdf 88 | *.sdf 89 | *.cachefile 90 | *.VC.db 91 | *.VC.VC.opendb 92 | 93 | # Visual Studio profiler 94 | *.psess 95 | *.vsp 96 | *.vspx 97 | *.sap 98 | 99 | # TFS 2012 Local Workspace 100 | $tf/ 101 | 102 | # Guidance Automation Toolkit 103 | *.gpState 104 | 105 | # ReSharper is a .NET coding add-in 106 | _ReSharper*/ 107 | *.[Rr]e[Ss]harper 108 | *.DotSettings.user 109 | 110 | # JustCode is a .NET coding add-in 111 | .JustCode 112 | 113 | # TeamCity is a build add-in 114 | _TeamCity* 115 | 116 | # DotCover is a Code Coverage Tool 117 | *.dotCover 118 | 119 | # Visual Studio code coverage results 120 | *.coverage 121 | *.coveragexml 122 | 123 | # NCrunch 124 | _NCrunch_* 125 | .*crunch*.local.xml 126 | nCrunchTemp_* 127 | 128 | # MightyMoose 129 | *.mm.* 130 | AutoTest.Net/ 131 | 132 | # Web workbench (sass) 133 | .sass-cache/ 134 | 135 | # Installshield output folder 136 | [Ee]xpress/ 137 | 138 | # DocProject is a documentation generator add-in 139 | DocProject/buildhelp/ 140 | DocProject/Help/*.HxT 141 | DocProject/Help/*.HxC 142 | DocProject/Help/*.hhc 143 | DocProject/Help/*.hhk 144 | DocProject/Help/*.hhp 145 | DocProject/Help/Html2 146 | DocProject/Help/html 147 | 148 | # Click-Once directory 149 | publish/ 150 | 151 | # Publish Web Output 152 | *.[Pp]ublish.xml 153 | *.azurePubxml 154 | # TODO: Comment the next line if you want to checkin your web deploy settings 155 | # but database connection strings (with potential passwords) will be unencrypted 156 | *.pubxml 157 | *.publishproj 158 | 159 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 160 | # checkin your Azure Web App publish settings, but sensitive information contained 161 | # in these scripts will be unencrypted 162 | PublishScripts/ 163 | 164 | # NuGet Packages 165 | *.nupkg 166 | # The packages folder can be ignored because of Package Restore 167 | **/packages/* 168 | # except build/, which is used as an MSBuild target. 169 | !**/packages/build/ 170 | # Uncomment if necessary however generally it will be regenerated when needed 171 | #!**/packages/repositories.config 172 | # NuGet v3's project.json files produces more ignorable files 173 | *.nuget.props 174 | *.nuget.targets 175 | 176 | # Microsoft Azure Build Output 177 | csx/ 178 | *.build.csdef 179 | 180 | # Microsoft Azure Emulator 181 | ecf/ 182 | rcf/ 183 | 184 | # Windows Store app package directories and files 185 | AppPackages/ 186 | BundleArtifacts/ 187 | Package.StoreAssociation.xml 188 | _pkginfo.txt 189 | 190 | # Visual Studio cache files 191 | # files ending in .cache can be ignored 192 | *.[Cc]ache 193 | # but keep track of directories ending in .cache 194 | !*.[Cc]ache/ 195 | 196 | # Others 197 | ClientBin/ 198 | ~$* 199 | *~ 200 | *.dbmdl 201 | *.dbproj.schemaview 202 | *.jfm 203 | *.pfx 204 | *.publishsettings 205 | orleans.codegen.cs 206 | 207 | # Since there are multiple workflows, uncomment next line to ignore bower_components 208 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 209 | #bower_components/ 210 | 211 | # RIA/Silverlight projects 212 | Generated_Code/ 213 | 214 | # Backup & report files from converting an old project file 215 | # to a newer Visual Studio version. Backup files are not needed, 216 | # because we have git ;-) 217 | _UpgradeReport_Files/ 218 | Backup*/ 219 | UpgradeLog*.XML 220 | UpgradeLog*.htm 221 | 222 | # SQL Server files 223 | *.mdf 224 | *.ldf 225 | *.ndf 226 | 227 | # Business Intelligence projects 228 | *.rdl.data 229 | *.bim.layout 230 | *.bim_*.settings 231 | 232 | # Microsoft Fakes 233 | FakesAssemblies/ 234 | 235 | # GhostDoc plugin setting file 236 | *.GhostDoc.xml 237 | 238 | # Node.js Tools for Visual Studio 239 | .ntvs_analysis.dat 240 | node_modules/ 241 | 242 | # Typescript v1 declaration files 243 | typings/ 244 | 245 | # Visual Studio 6 build log 246 | *.plg 247 | 248 | # Visual Studio 6 workspace options file 249 | *.opt 250 | 251 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 252 | *.vbw 253 | 254 | # Visual Studio LightSwitch build output 255 | **/*.HTMLClient/GeneratedArtifacts 256 | **/*.DesktopClient/GeneratedArtifacts 257 | **/*.DesktopClient/ModelManifest.xml 258 | **/*.Server/GeneratedArtifacts 259 | **/*.Server/ModelManifest.xml 260 | _Pvt_Extensions 261 | 262 | # Paket dependency manager 263 | .paket/paket.exe 264 | paket-files/ 265 | 266 | # FAKE - F# Make 267 | .fake/ 268 | 269 | # JetBrains Rider 270 | .idea/ 271 | *.sln.iml 272 | 273 | # CodeRush 274 | .cr/ 275 | 276 | # Python Tools for Visual Studio (PTVS) 277 | __pycache__/ 278 | *.pyc 279 | 280 | # Cake - Uncomment if you are using it 281 | # tools/** 282 | # !tools/packages.config 283 | 284 | # Telerik's JustMock configuration file 285 | *.jmconfig 286 | 287 | # BizTalk build output 288 | *.btp.cs 289 | *.btm.cs 290 | *.odx.cs 291 | *.xsd.cs 292 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "CosmosDbContext"] 2 | path = CosmosDbContext 3 | url = https://github.com/conwid/CosmosDbContext.git 4 | [submodule "CosmosDbAdoNetProvider"] 5 | path = CosmosDbAdoNetProvider 6 | url = https://github.com/conwid/CosmosDbAdoNetProvider.git 7 | -------------------------------------------------------------------------------- /AzureCosmosDbDriver.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27428.2037 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureCosmosDbDriver", "AzureDocumentDbDriver\AzureCosmosDbDriver.csproj", "{634AB57F-E052-459E-BC22-24933427D302}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CosmosDbAdoNetProvider", "CosmosDbAdoNetProvider\CosmosDbAdoNetProvider.csproj", "{4E685226-1E96-4E98-82EC-A70F1041C920}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CosmosDbContext", "CosmosDbContext\CosmosDbContext.csproj", "{53C30B69-E08D-4A09-B996-21D3ED30E37D}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {634AB57F-E052-459E-BC22-24933427D302}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {634AB57F-E052-459E-BC22-24933427D302}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {634AB57F-E052-459E-BC22-24933427D302}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {634AB57F-E052-459E-BC22-24933427D302}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {4E685226-1E96-4E98-82EC-A70F1041C920}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {4E685226-1E96-4E98-82EC-A70F1041C920}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {4E685226-1E96-4E98-82EC-A70F1041C920}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {4E685226-1E96-4E98-82EC-A70F1041C920}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {53C30B69-E08D-4A09-B996-21D3ED30E37D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {53C30B69-E08D-4A09-B996-21D3ED30E37D}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {53C30B69-E08D-4A09-B996-21D3ED30E37D}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {53C30B69-E08D-4A09-B996-21D3ED30E37D}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {68C0AE25-FD57-464A-A5B7-46C740DA53CD} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /AzureDocumentDbDriver/AzureCosmosDbDriver.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {634AB57F-E052-459E-BC22-24933427D302} 8 | Library 9 | Properties 10 | AzureCosmosDbDriver 11 | AzureCosmosDbDriver 12 | v4.7.1 13 | 512 14 | 15 | 16 | 17 | 18 | 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | true 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | C:\Program Files (x86)\LINQPad5\LINQPad.exe 45 | 46 | 47 | ..\packages\Microsoft.Azure.DocumentDB.1.22.0\lib\net45\Microsoft.Azure.Documents.Client.dll 48 | 49 | 50 | ..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll 51 | True 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | MSBuild:Compile 69 | Designer 70 | 71 | 72 | MSBuild:Compile 73 | Designer 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | Dynamic\ConnectionDialog.xaml 82 | Code 83 | 84 | 85 | 86 | 87 | Static\ConnectionDialog.xaml 88 | Code 89 | 90 | 91 | 92 | 93 | 94 | Always 95 | 96 | 97 | Always 98 | 99 | 100 | Always 101 | Designer 102 | 103 | 104 | 105 | 106 | Designer 107 | 108 | 109 | Always 110 | 111 | 112 | 113 | Always 114 | 115 | 116 | 117 | 118 | {4E685226-1E96-4E98-82EC-A70F1041C920} 119 | CosmosDbAdoNetProvider 120 | 121 | 122 | {53C30B69-E08D-4A09-B996-21D3ED30E37D} 123 | CosmosDbContext 124 | 125 | 126 | 127 | 128 | if $(ConfigurationName) == Debug DevDeploy.bat 129 | if $(ConfigurationName) == Release powershell.exe -NonInteractive -executionPolicy Unrestricted -file "ReleaseDeploy.ps1" -folder "$(TargetDir) 130 | 131 | 132 | 133 | 134 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 135 | 136 | 137 | 138 | 145 | -------------------------------------------------------------------------------- /AzureDocumentDbDriver/Common/DriverHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using LINQPad.Extensibility.DataContext; 7 | using System.Dynamic; 8 | using System.Data.Common; 9 | using System.Data; 10 | using CosmosDbAdoNetProvider; 11 | 12 | namespace AzureCosmosDbDriver.Common 13 | { 14 | public static class DriverHelper 15 | { 16 | public static string AuthorName => "Akos Nagy"; 17 | 18 | public static IEnumerable GetAssembliesToAdd() => 19 | new[] 20 | { 21 | "Microsoft.Azure.Documents.Client.dll", 22 | "Newtonsoft.Json.dll", 23 | "CosmosDbAdoNetProvider.dll", 24 | "CosmosDbContext.dll" 25 | }; 26 | 27 | 28 | public static IEnumerable GetNamespaceToAdd() => 29 | new[] 30 | { 31 | "Microsoft.Azure.Documents.Client", 32 | "System.Dynamic", 33 | "System.Collections.Generic", 34 | "CosmosDbContext", 35 | "CosmosDbContext.Collection" 36 | }; 37 | 38 | 39 | public static string GetConnectionDescription(IConnectionInfo cxInfo) 40 | { 41 | var props = new Properties(cxInfo); 42 | return $"{props.Uri}/{props.Database}"; 43 | } 44 | 45 | public static ParameterDescriptor[] GetContextConstructorParameters(IConnectionInfo cxInfo) 46 | { 47 | var stringTypeName = typeof(string).FullName; 48 | return new[] { 49 | new ParameterDescriptor("uri", stringTypeName), 50 | new ParameterDescriptor("authKey", stringTypeName), 51 | new ParameterDescriptor("database", stringTypeName) 52 | }; 53 | } 54 | 55 | internal static IDbConnection GetIDbConnection(IConnectionInfo cxInfo) 56 | { 57 | var props = new Properties(cxInfo); 58 | return new CosmosDbSqlConnection(props.Uri, props.AccountKey, props.Database); 59 | } 60 | 61 | public static DbProviderFactory GetProviderFactory(IConnectionInfo cxInfo) 62 | { 63 | if (cxInfo.DatabaseInfo.Provider != CosmosDbSqlProviderFactory.ProviderName) 64 | { 65 | throw new NotSupportedException($"Only {CosmosDbSqlProviderFactory.ProviderName} is supported; requested {cxInfo.DatabaseInfo.Provider}"); 66 | } 67 | var props = new Properties(cxInfo); 68 | return new CosmosDbSqlProviderFactory(props.Uri, props.AccountKey, props.Database); 69 | } 70 | 71 | public static object[] GetContextConstructorArguments(IConnectionInfo cxInfo) 72 | { 73 | var props = new Properties(cxInfo); 74 | return new object[] { props.Uri, props.AccountKey, props.Database }; 75 | } 76 | 77 | internal static bool AreRepositoriesEquivalent(IConnectionInfo c1, IConnectionInfo c2) 78 | { 79 | var p1 = new Properties(c1); 80 | var p2 = new Properties(c2); 81 | return p1.AccountKey == p2.AccountKey; 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /AzureDocumentDbDriver/Common/Properties.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | using System.Xml.Linq; 3 | using LINQPad.Extensibility.DataContext; 4 | 5 | namespace AzureCosmosDbDriver.Common 6 | { 7 | 8 | public class Properties 9 | { 10 | private readonly IConnectionInfo cxInfo; 11 | private readonly XElement driverData; 12 | 13 | public Properties(IConnectionInfo cxInfo) 14 | { 15 | this.cxInfo = cxInfo; 16 | driverData = cxInfo.DriverData; 17 | } 18 | 19 | public ICustomTypeInfo CustomTypeInfo => cxInfo.CustomTypeInfo; 20 | 21 | public bool Persist 22 | { 23 | get => cxInfo.Persist; 24 | set => cxInfo.Persist = value; 25 | } 26 | 27 | public string Uri 28 | { 29 | get => (string)driverData.Element(nameof(Uri)) ?? string.Empty; 30 | set => driverData.SetElementValue(nameof(Uri), value); 31 | } 32 | 33 | public string AccountKey 34 | { 35 | get => (string)driverData.Element(nameof(AccountKey)) ?? string.Empty; 36 | set => driverData.SetElementValue(nameof(AccountKey), value); 37 | } 38 | 39 | public string Database 40 | { 41 | get => (string)driverData.Element(nameof(Database)) ?? string.Empty; 42 | set => driverData.SetElementValue(nameof(Database), value); 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /AzureDocumentDbDriver/Common/SchemaBuilder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom.Compiler; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Reflection; 7 | using System.Xml; 8 | using System.Xml.Linq; 9 | using LINQPad.Extensibility.DataContext; 10 | using Microsoft.CSharp; 11 | using Microsoft.Azure.Documents; 12 | using Microsoft.Azure.Documents.Client; 13 | 14 | namespace AzureCosmosDbDriver.Common 15 | { 16 | public static class SchemaBuilder 17 | { 18 | public static List GetSchema(Properties props) 19 | { 20 | using (var client = new DocumentClient(new Uri(props.Uri), props.AccountKey)) 21 | { 22 | var database = client.CreateDatabaseQuery().AsEnumerable().Single(db => db.Id == props.Database); 23 | ExplorerItem dbItem = new ExplorerItem(database.Id, ExplorerItemKind.Schema, ExplorerIcon.Schema) { Children = new List() }; 24 | var collections = client.CreateDocumentCollectionQuery(database.SelfLink).ToList(); 25 | foreach (var collection in collections) 26 | { 27 | var collectionItem = new ExplorerItem(collection.Id, ExplorerItemKind.QueryableObject, ExplorerIcon.Table) { IsEnumerable = true, Tag = collection.Id, Children = new List() }; 28 | dbItem.Children.Add(collectionItem); 29 | var sps = client.CreateStoredProcedureQuery(collection.SelfLink); 30 | var storedProceduresCategory = new ExplorerItem("Stored procedures", ExplorerItemKind.Category, ExplorerIcon.StoredProc) { Children = new List() }; 31 | foreach (var sp in sps) 32 | { 33 | storedProceduresCategory.Children.Add(new ExplorerItem(sp.Id, ExplorerItemKind.QueryableObject, ExplorerIcon.StoredProc) { IsEnumerable = true, Tag = sp.Id, DragText = sp.Id, ToolTipText = sp.Body }); 34 | } 35 | 36 | var udfs = client.CreateUserDefinedFunctionQuery(collection.SelfLink); 37 | var udfsCategory = new ExplorerItem("User-defined functions", ExplorerItemKind.Category, ExplorerIcon.ScalarFunction) { Children = new List() }; 38 | foreach (var udf in udfs) 39 | { 40 | udfsCategory.Children.Add(new ExplorerItem(udf.Id, ExplorerItemKind.QueryableObject, ExplorerIcon.ScalarFunction) { IsEnumerable = true, Tag = udf.Id, DragText = "SELECT udf." + udf.Id, ToolTipText = udf.Body }); 41 | } 42 | collectionItem.Children.Add(storedProceduresCategory); 43 | collectionItem.Children.Add(udfsCategory); 44 | } 45 | return new List { dbItem }; 46 | } 47 | } 48 | public static List GetSchemaAndBuildAssembly(Properties props, AssemblyName name, ref string nameSpace, ref string typeName, string driverFolder) 49 | { 50 | var items = GetSchema(props); 51 | string code = GenerateCode(items[0].Children, nameSpace, typeName, props.Database); 52 | BuildAssembly(code, name, driverFolder); 53 | return items; 54 | } 55 | 56 | private static string GenerateCode(IEnumerable collections, string @namepace, string typeName, string database) 57 | { 58 | string code = $"namespace {@namepace} {{"; 59 | code = code + "using Microsoft.Azure.Documents.Client;" + 60 | "using System;" + 61 | "using System.Linq; " + 62 | "using System.Dynamic;" + 63 | "using System.Collections.Generic;" + 64 | "using CosmosDbContext.Collection;"; 65 | 66 | code = code + $"public abstract class {typeName} : CosmosDbContext.CosmosDbContext" + 67 | $"{{public {typeName}(string uri, string authKey, string database) : base (uri,authKey,database) {{}}"; 68 | foreach (var collection in collections) 69 | { 70 | code = code + $" [CosmosDbCollection] public ICosmosDbCollection {collection.Tag} {{ get; set; }}"; 71 | foreach (var sp in collection.Children.Single(s => s.Text == "Stored procedures").Children) 72 | { 73 | code = code + $" public IEnumerable {collection.Tag}_{sp.Tag}(params dynamic[] parameters)" + 74 | "{" + 75 | $" return base.ExecuteDynamicStoredProcedure(\"{sp.Tag}\",\"{collection.Tag}\", parameters).ToList();" + 76 | "}"; 77 | } 78 | } 79 | code = code + "}}"; 80 | return code; 81 | } 82 | 83 | private static void BuildAssembly(string code, AssemblyName name, string driverFolder) 84 | { 85 | #if DEBUG 86 | bool includeDebug = true; 87 | #else 88 | bool includeDebug = false; 89 | #endif 90 | CompilerResults results; 91 | using (var codeProvider = new CSharpCodeProvider(new Dictionary() { { "CompilerVersion", "v4.0" } })) 92 | { 93 | var dependencies = new string[] { 94 | "System.dll", 95 | "System.Core.dll", 96 | "System.Xml.dll", 97 | Path.Combine(driverFolder,"Microsoft.Azure.Documents.Client.dll"), 98 | Path.Combine(driverFolder,"Newtonsoft.Json.dll"), 99 | Path.Combine(driverFolder,"CosmosDbContext.dll"), 100 | Path.Combine(driverFolder,"CosmosDbAdoNetProvider.dll"), 101 | }; 102 | var options = new CompilerParameters(dependencies, name.CodeBase, includeDebug); 103 | results = codeProvider.CompileAssemblyFromSource(options, code); 104 | } 105 | if (results.Errors.Count > 0) 106 | { 107 | throw new Exception("Cannot compile typed context: " + results.Errors[0].ErrorText + " (line " + results.Errors[0].Line + ")"); 108 | } 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /AzureDocumentDbDriver/Connection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/conwid/AzureDocumentDbDriver/f3934407aceccc91dd843c1d189d53a50d050bb5/AzureDocumentDbDriver/Connection.png -------------------------------------------------------------------------------- /AzureDocumentDbDriver/DevDeploy.bat: -------------------------------------------------------------------------------- 1 | xcopy /i/y *.dll "%localappdata%\LINQPad\Drivers\DataContext\4.6\AzureCosmosDbDriver (no-strong-name)\" 2 | xcopy /i/y *.pdb "%localappdata%\LINQPad\Drivers\DataContext\4.6\AzureCosmosDbDriver (no-strong-name)\" 3 | -------------------------------------------------------------------------------- /AzureDocumentDbDriver/Dynamic/ConnectionDialog.xaml: -------------------------------------------------------------------------------- 1 |  7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | Remember this connection 19 | 20 | 21 |