diff --git a/Docs/Jupyter笔记.1.2.连接数据库.ipynb b/Docs/Jupyter笔记.1.2.连接数据库.ipynb index d2c05d9..03148bf 100644 --- a/Docs/Jupyter笔记.1.2.连接数据库.ipynb +++ b/Docs/Jupyter笔记.1.2.连接数据库.ipynb @@ -48,19 +48,46 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" - }, - "vscode": { - "languageId": "polyglot-notebook" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "<div><div></div><div></div><div><strong>Installed Packages</strong><ul><li><span>Microsoft.Dotnet.Interactive.SqlServer, 1.0.0-beta.23165.2</span></li></ul></div></div>" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Loading extensions from `C:\\Users\\ruyu\\.nuget\\packages\\microsoft.dotnet.interactive.sqlserver\\1.0.0-beta.23165.2\\interactive-extensions\\dotnet\\Microsoft.DotNet.Interactive.SqlServer.dll`" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "<details><summary>Query Microsoft SQL Server databases.</summary>\r\n", + "<p>This extension adds support for connecting to Microsoft SQL Server databases using the <code>#!connect mssql</code> magic command. For more information, run a cell using the <code>#!sql</code> magic command.</p>\r\n", + "</details>" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "#r \"nuget:Microsoft.Dotnet.Interactive.SqlServer,*-*\"" ] @@ -134,9 +161,6 @@ }, "polyglot_notebook": { "kernelName": "csharp" - }, - "vscode": { - "languageId": "polyglot-notebook" } }, "outputs": [], @@ -192,21 +216,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" - }, - "vscode": { - "languageId": "polyglot-notebook" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "Kernel added: #!sql-Demo" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ - "#!connect mssql \"server=.\\SQL2008;uid=sa;pwd=gly-bicijinlian;database=Demo;Encrypt=True;TrustServerCertificate=True;\" --kernel-name Demo\n", + "#!connect mssql \"server=.\\SQL2008;uid=sa;pwd=gly-bicijinlian;database=Study;Encrypt=True;TrustServerCertificate=True;\" --kernel-name Demo\n", "//重复执行会抛出错误,目前没有找到解决方法" ] }, @@ -242,21 +273,73 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "dotnet_interactive": { "language": "sql-Demo" }, "polyglot_notebook": { "kernelName": "sql-Demo" - }, - "vscode": { - "languageId": "polyglot-notebook" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "(2 行受到影响)" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/csv": [ + "Id,Name,Age,Address,School,Grade,Room\r\n", + "1,王明明,5,五星小区21号301,太康一高,一年级,\r\n", + "2,张三丰,9,,太康一高,一年级,\r\n" + ], + "text/html": [ + "<table><thead><tr><td><span>Id</span></td><td><span>Name</span></td><td><span>Age</span></td><td><span>Address</span></td><td><span>School</span></td><td><span>Grade</span></td><td><span>Room</span></td></tr></thead><tbody><tr><td><div class=\"dni-plaintext\"><pre>1</pre></div></td><td>王明明</td><td><div class=\"dni-plaintext\"><pre>5</pre></div></td><td>五星小区21号301</td><td>太康一高</td><td>一年级</td><td></td></tr><tr><td><div class=\"dni-plaintext\"><pre>2</pre></div></td><td>张三丰</td><td><div class=\"dni-plaintext\"><pre>9</pre></div></td><td></td><td>太康一高</td><td>一年级</td><td></td></tr></tbody></table><style>\r\n", + ".dni-code-hint {\r\n", + " font-style: italic;\r\n", + " overflow: hidden;\r\n", + " white-space: nowrap;\r\n", + "}\r\n", + ".dni-treeview {\r\n", + " white-space: nowrap;\r\n", + "}\r\n", + ".dni-treeview td {\r\n", + " vertical-align: top;\r\n", + " text-align: start;\r\n", + "}\r\n", + "details.dni-treeview {\r\n", + " padding-left: 1em;\r\n", + "}\r\n", + "table td {\r\n", + " text-align: start;\r\n", + "}\r\n", + "table tr { \r\n", + " vertical-align: top; \r\n", + " margin: 0em 0px;\r\n", + "}\r\n", + "table tr td pre \r\n", + "{ \r\n", + " vertical-align: top !important; \r\n", + " margin: 0em 0px !important;\r\n", + "} \r\n", + "table th {\r\n", + " text-align: start;\r\n", + "}\r\n", + "</style>" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ - "SELECT * from Test" + "SELECT * from Student" ] }, { @@ -291,22 +374,74 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" - }, - "vscode": { - "languageId": "polyglot-notebook" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "(2 行受到影响)" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/csv": [ + "Id,Name,Age,Address,School,Grade,Room\r\n", + "1,王明明,5,五星小区21号301,太康一高,一年级,\r\n", + "2,张三丰,9,,太康一高,一年级,\r\n" + ], + "text/html": [ + "<table><thead><tr><td><span>Id</span></td><td><span>Name</span></td><td><span>Age</span></td><td><span>Address</span></td><td><span>School</span></td><td><span>Grade</span></td><td><span>Room</span></td></tr></thead><tbody><tr><td><div class=\"dni-plaintext\"><pre>1</pre></div></td><td>王明明</td><td><div class=\"dni-plaintext\"><pre>5</pre></div></td><td>五星小区21号301</td><td>太康一高</td><td>一年级</td><td></td></tr><tr><td><div class=\"dni-plaintext\"><pre>2</pre></div></td><td>张三丰</td><td><div class=\"dni-plaintext\"><pre>9</pre></div></td><td></td><td>太康一高</td><td>一年级</td><td></td></tr></tbody></table><style>\r\n", + ".dni-code-hint {\r\n", + " font-style: italic;\r\n", + " overflow: hidden;\r\n", + " white-space: nowrap;\r\n", + "}\r\n", + ".dni-treeview {\r\n", + " white-space: nowrap;\r\n", + "}\r\n", + ".dni-treeview td {\r\n", + " vertical-align: top;\r\n", + " text-align: start;\r\n", + "}\r\n", + "details.dni-treeview {\r\n", + " padding-left: 1em;\r\n", + "}\r\n", + "table td {\r\n", + " text-align: start;\r\n", + "}\r\n", + "table tr { \r\n", + " vertical-align: top; \r\n", + " margin: 0em 0px;\r\n", + "}\r\n", + "table tr td pre \r\n", + "{ \r\n", + " vertical-align: top !important; \r\n", + " margin: 0em 0px !important;\r\n", + "} \r\n", + "table th {\r\n", + " text-align: start;\r\n", + "}\r\n", + "</style>" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "#!sql-Demo\n", - "SELECT * from Test" + "SELECT * from Student" ] }, { @@ -341,21 +476,53 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" - }, - "vscode": { - "languageId": "polyglot-notebook" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/markdown": [ + "Scaffolding a `DbContext` and initializing an instance of it called `DemoEF` in the C# kernel." + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "<div><div></div><div></div><div><strong>Installed Packages</strong><ul><li><span>Humanizer, 2.14.1</span></li><li><span>humanizer.core, 2.14.1</span></li><li><span>Microsoft.EntityFrameworkCore.Design, 7.0.0</span></li><li><span>microsoft.entityframeworkcore.sqlserver, 7.0.0</span></li><li><span>microsoft.identity.client, 4.48.1</span></li></ul></div></div>" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Security Warning: The negotiated TLS 1.0 is an insecure protocol and is supported for backward compatibility only. The recommended protocol version is TLS 1.2 and later.\r\n" + ] + }, + { + "data": { + "text/plain": [ + "Kernel added: #!sql-DemoEF" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ - "#!connect mssql \"server=.\\SQL2008;uid=sa;pwd=gly-bicijinlian;database=Demo;Encrypt=True;TrustServerCertificate=True;\" --create-dbcontext --kernel-name DemoEF " + "#!connect mssql \"server=.\\SQL2008;uid=sa;pwd=gly-bicijinlian;database=Study;Encrypt=True;TrustServerCertificate=True;\" --create-dbcontext --kernel-name DemoEF " ] }, { @@ -408,22 +575,74 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" - }, - "vscode": { - "languageId": "polyglot-notebook" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "(2 行受到影响)" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/csv": [ + "Id,Name,Age,Address,School,Grade,Room\r\n", + "1,王明明,5,五星小区21号301,太康一高,一年级,\r\n", + "2,张三丰,9,,太康一高,一年级,\r\n" + ], + "text/html": [ + "<table><thead><tr><td><span>Id</span></td><td><span>Name</span></td><td><span>Age</span></td><td><span>Address</span></td><td><span>School</span></td><td><span>Grade</span></td><td><span>Room</span></td></tr></thead><tbody><tr><td><div class=\"dni-plaintext\"><pre>1</pre></div></td><td>王明明</td><td><div class=\"dni-plaintext\"><pre>5</pre></div></td><td>五星小区21号301</td><td>太康一高</td><td>一年级</td><td></td></tr><tr><td><div class=\"dni-plaintext\"><pre>2</pre></div></td><td>张三丰</td><td><div class=\"dni-plaintext\"><pre>9</pre></div></td><td></td><td>太康一高</td><td>一年级</td><td></td></tr></tbody></table><style>\r\n", + ".dni-code-hint {\r\n", + " font-style: italic;\r\n", + " overflow: hidden;\r\n", + " white-space: nowrap;\r\n", + "}\r\n", + ".dni-treeview {\r\n", + " white-space: nowrap;\r\n", + "}\r\n", + ".dni-treeview td {\r\n", + " vertical-align: top;\r\n", + " text-align: start;\r\n", + "}\r\n", + "details.dni-treeview {\r\n", + " padding-left: 1em;\r\n", + "}\r\n", + "table td {\r\n", + " text-align: start;\r\n", + "}\r\n", + "table tr { \r\n", + " vertical-align: top; \r\n", + " margin: 0em 0px;\r\n", + "}\r\n", + "table tr td pre \r\n", + "{ \r\n", + " vertical-align: top !important; \r\n", + " margin: 0em 0px !important;\r\n", + "} \r\n", + "table th {\r\n", + " text-align: start;\r\n", + "}\r\n", + "</style>" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "#!sql-DemoEF\n", - "SELECT * from Test" + "SELECT * from Student" ] }, { @@ -443,26 +662,104 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" - }, - "vscode": { - "languageId": "polyglot-notebook" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "<table><thead><tr><th><i>index</i></th><th>value</th></tr></thead><tbody><tr><td>0</td><td><details class=\"dni-treeview\"><summary><span class=\"dni-code-hint\"><code>Submission#4+Student</code></span></summary><div><table><thead><tr></tr></thead><tbody><tr><td>Id</td><td><div class=\"dni-plaintext\"><pre>1</pre></div></td></tr><tr><td>Name</td><td>王明明</td></tr><tr><td>Age</td><td><div class=\"dni-plaintext\"><pre>5</pre></div></td></tr><tr><td>Address</td><td>五星小区21号301</td></tr><tr><td>School</td><td>太康一高</td></tr><tr><td>Grade</td><td>一年级</td></tr><tr><td>Room</td><td></td></tr></tbody></table></div></details></td></tr><tr><td>1</td><td><details class=\"dni-treeview\"><summary><span class=\"dni-code-hint\"><code>Submission#4+Student</code></span></summary><div><table><thead><tr></tr></thead><tbody><tr><td>Id</td><td><div class=\"dni-plaintext\"><pre>2</pre></div></td></tr><tr><td>Name</td><td>张三丰</td></tr><tr><td>Age</td><td><div class=\"dni-plaintext\"><pre>9</pre></div></td></tr><tr><td>Address</td><td></td></tr><tr><td>School</td><td>太康一高</td></tr><tr><td>Grade</td><td>一年级</td></tr><tr><td>Room</td><td></td></tr></tbody></table></div></details></td></tr></tbody></table><style>\r\n", + ".dni-code-hint {\r\n", + " font-style: italic;\r\n", + " overflow: hidden;\r\n", + " white-space: nowrap;\r\n", + "}\r\n", + ".dni-treeview {\r\n", + " white-space: nowrap;\r\n", + "}\r\n", + ".dni-treeview td {\r\n", + " vertical-align: top;\r\n", + " text-align: start;\r\n", + "}\r\n", + "details.dni-treeview {\r\n", + " padding-left: 1em;\r\n", + "}\r\n", + "table td {\r\n", + " text-align: start;\r\n", + "}\r\n", + "table tr { \r\n", + " vertical-align: top; \r\n", + " margin: 0em 0px;\r\n", + "}\r\n", + "table tr td pre \r\n", + "{ \r\n", + " vertical-align: top !important; \r\n", + " margin: 0em 0px !important;\r\n", + "} \r\n", + "table th {\r\n", + " text-align: start;\r\n", + "}\r\n", + "</style>" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "<div class=\"dni-plaintext\"><pre>-1</pre></div><style>\r\n", + ".dni-code-hint {\r\n", + " font-style: italic;\r\n", + " overflow: hidden;\r\n", + " white-space: nowrap;\r\n", + "}\r\n", + ".dni-treeview {\r\n", + " white-space: nowrap;\r\n", + "}\r\n", + ".dni-treeview td {\r\n", + " vertical-align: top;\r\n", + " text-align: start;\r\n", + "}\r\n", + "details.dni-treeview {\r\n", + " padding-left: 1em;\r\n", + "}\r\n", + "table td {\r\n", + " text-align: start;\r\n", + "}\r\n", + "table tr { \r\n", + " vertical-align: top; \r\n", + " margin: 0em 0px;\r\n", + "}\r\n", + "table tr td pre \r\n", + "{ \r\n", + " vertical-align: top !important; \r\n", + " margin: 0em 0px !important;\r\n", + "} \r\n", + "table th {\r\n", + " text-align: start;\r\n", + "}\r\n", + "</style>" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "//连接建立后,执行环境中就有了相关的类:DBContext等\n", "DemoEFContext context = new DemoEFContext();\n", - "var t = context.Tests.ToList<Test>();\n", + "var t = context.Students.ToList<Student>();\n", "display(t);\n", "\n", - "FormattableString fs = $\"select * from Test;\";\n", + "FormattableString fs = $\"select * from Student;\";\n", "var c = context.Database.ExecuteSql(fs);\n", "display(c);" ] @@ -474,39 +771,29 @@ "language": "C#", "name": ".net-csharp" }, + "language_info": { + "name": "polyglot-notebook" + }, "polyglot_notebook": { "kernelInfo": { "defaultKernelName": "csharp", "items": [ - { - "aliases": [ - "c#", - "C#" - ], - "languageName": "C#", - "name": "csharp" - }, { "aliases": [], - "languageName": "SQL", - "name": "sql" + "name": ".NET" }, { "aliases": [ - "frontend" + "C#", + "c#" ], - "languageName": null, - "name": "vscode" - }, - { - "aliases": [], - "languageName": null, - "name": ".NET" + "languageName": "C#", + "name": "csharp" }, { "aliases": [ - "f#", - "F#" + "F#", + "f#" ], "languageName": "F#", "name": "fsharp" @@ -533,9 +820,30 @@ "languageName": "PowerShell", "name": "pwsh" }, + { + "aliases": [], + "languageName": "SQL", + "name": "sql" + }, + { + "aliases": [], + "languageName": "T-SQL", + "name": "sql-Demo" + }, + { + "aliases": [], + "languageName": "T-SQL", + "name": "sql-DemoEF" + }, { "aliases": [], "name": "value" + }, + { + "aliases": [ + "frontend" + ], + "name": "vscode" } ] } diff --git a/MultiThreadingStudy.ConsoleApp/Program.cs b/MultiThreadingStudy.ConsoleApp/Program.cs index 20aa618..63b6bc2 100644 --- a/MultiThreadingStudy.ConsoleApp/Program.cs +++ b/MultiThreadingStudy.ConsoleApp/Program.cs @@ -2,7 +2,7 @@ namespace MultiThreadingStudy.ConsoleApp { internal class Program { - static async Task Main(string[] args) + static void Main(string[] args) { Console.WriteLine("多线程学习"); }