|
|
|
@ -0,0 +1,655 @@
|
|
|
|
|
{
|
|
|
|
|
"cells": [
|
|
|
|
|
{
|
|
|
|
|
"attachments": {},
|
|
|
|
|
"cell_type": "markdown",
|
|
|
|
|
"metadata": {
|
|
|
|
|
"dotnet_interactive": {
|
|
|
|
|
"language": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "csharp"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"source": [
|
|
|
|
|
"连接数据库\n",
|
|
|
|
|
"==============================\n",
|
|
|
|
|
"连接到SQL Server,并操作数据。 "
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "markdown",
|
|
|
|
|
"metadata": {
|
|
|
|
|
"dotnet_interactive": {
|
|
|
|
|
"language": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "csharp"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"source": [
|
|
|
|
|
"+ 引用操作类库"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": null,
|
|
|
|
|
"metadata": {
|
|
|
|
|
"dotnet_interactive": {
|
|
|
|
|
"language": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"vscode": {
|
|
|
|
|
"languageId": "polyglot-notebook"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"outputs": [],
|
|
|
|
|
"source": [
|
|
|
|
|
"#r \"nuget:Microsoft.Dotnet.Interactive.SqlServer,*-*\""
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"attachments": {},
|
|
|
|
|
"cell_type": "markdown",
|
|
|
|
|
"metadata": {
|
|
|
|
|
"dotnet_interactive": {
|
|
|
|
|
"language": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "csharp"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"source": [
|
|
|
|
|
"+ 连接到SQL Server\n",
|
|
|
|
|
" > 数据库连接命令为 `#!connect` 查看连接帮助 `#!connect -h`"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": null,
|
|
|
|
|
"metadata": {
|
|
|
|
|
"dotnet_interactive": {
|
|
|
|
|
"language": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"vscode": {
|
|
|
|
|
"languageId": "polyglot-notebook"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"outputs": [],
|
|
|
|
|
"source": [
|
|
|
|
|
"#!connect -h\n"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"attachments": {},
|
|
|
|
|
"cell_type": "markdown",
|
|
|
|
|
"metadata": {
|
|
|
|
|
"dotnet_interactive": {
|
|
|
|
|
"language": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "csharp"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"source": [
|
|
|
|
|
"> 连接到本机SQL Server, 特别注意的是 --kernel-name 指定名称,后面的SQL操作均需要使用:sql-{{kernel-name}}的值\n",
|
|
|
|
|
"> 比如 --kernel-name Demo, 则该SQL连接的kernel名称为 sql-Demo, 使用 #!sql-Demo 进行引用"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": 2,
|
|
|
|
|
"metadata": {
|
|
|
|
|
"dotnet_interactive": {
|
|
|
|
|
"language": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"vscode": {
|
|
|
|
|
"languageId": "polyglot-notebook"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"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",
|
|
|
|
|
"\n",
|
|
|
|
|
"//重复执行会抛出错误,目前没有找到解决方法\n"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"attachments": {},
|
|
|
|
|
"cell_type": "markdown",
|
|
|
|
|
"metadata": {
|
|
|
|
|
"dotnet_interactive": {
|
|
|
|
|
"language": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "csharp"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"source": [
|
|
|
|
|
"+ 使用连接\n",
|
|
|
|
|
" 一种方法是:在右下角,切换 Kernel, 由 `csharp - C# Script` 换成 由--kernel-name指定值生成的 `sql-Demo - T-SQL`"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": 3,
|
|
|
|
|
"metadata": {
|
|
|
|
|
"dotnet_interactive": {
|
|
|
|
|
"language": "sql-Demo"
|
|
|
|
|
},
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "sql-Demo"
|
|
|
|
|
},
|
|
|
|
|
"vscode": {
|
|
|
|
|
"languageId": "polyglot-notebook"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"outputs": [
|
|
|
|
|
{
|
|
|
|
|
"data": {
|
|
|
|
|
"text/plain": [
|
|
|
|
|
"(4 行受到影响)"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
"metadata": {},
|
|
|
|
|
"output_type": "display_data"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"data": {
|
|
|
|
|
"text/csv": [
|
|
|
|
|
"Id,Name,Age\r\n",
|
|
|
|
|
"1,张三,20\r\n",
|
|
|
|
|
"2,李四,30\r\n",
|
|
|
|
|
"3,三丰,300\r\n",
|
|
|
|
|
"4,小龙子,50\r\n"
|
|
|
|
|
],
|
|
|
|
|
"text/html": [
|
|
|
|
|
"<table><thead><tr><td><span>Id</span></td><td><span>Name</span></td><td><span>Age</span></td></tr></thead><tbody><tr><td><div class=\"dni-plaintext\"><pre>1</pre></div></td><td>张三</td><td><div class=\"dni-plaintext\"><pre>20</pre></div></td></tr><tr><td><div class=\"dni-plaintext\"><pre>2</pre></div></td><td>李四</td><td><div class=\"dni-plaintext\"><pre>30</pre></div></td></tr><tr><td><div class=\"dni-plaintext\"><pre>3</pre></div></td><td>三丰</td><td><div class=\"dni-plaintext\"><pre>300</pre></div></td></tr><tr><td><div class=\"dni-plaintext\"><pre>4</pre></div></td><td>小龙子</td><td><div class=\"dni-plaintext\"><pre>50</pre></div></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"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "markdown",
|
|
|
|
|
"metadata": {
|
|
|
|
|
"dotnet_interactive": {
|
|
|
|
|
"language": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "csharp"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"source": [
|
|
|
|
|
"> 推荐的是下面的方法:即使用 `#!sql-Demo` ,后面直接写SQL语句,不用切换 kernel "
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": 4,
|
|
|
|
|
"metadata": {
|
|
|
|
|
"dotnet_interactive": {
|
|
|
|
|
"language": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"vscode": {
|
|
|
|
|
"languageId": "polyglot-notebook"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"outputs": [
|
|
|
|
|
{
|
|
|
|
|
"data": {
|
|
|
|
|
"text/plain": [
|
|
|
|
|
"(4 行受到影响)"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
"metadata": {},
|
|
|
|
|
"output_type": "display_data"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"data": {
|
|
|
|
|
"text/csv": [
|
|
|
|
|
"Id,Name,Age\r\n",
|
|
|
|
|
"1,张三,20\r\n",
|
|
|
|
|
"2,李四,30\r\n",
|
|
|
|
|
"3,三丰,300\r\n",
|
|
|
|
|
"4,小龙子,50\r\n"
|
|
|
|
|
],
|
|
|
|
|
"text/html": [
|
|
|
|
|
"<table><thead><tr><td><span>Id</span></td><td><span>Name</span></td><td><span>Age</span></td></tr></thead><tbody><tr><td><div class=\"dni-plaintext\"><pre>1</pre></div></td><td>张三</td><td><div class=\"dni-plaintext\"><pre>20</pre></div></td></tr><tr><td><div class=\"dni-plaintext\"><pre>2</pre></div></td><td>李四</td><td><div class=\"dni-plaintext\"><pre>30</pre></div></td></tr><tr><td><div class=\"dni-plaintext\"><pre>3</pre></div></td><td>三丰</td><td><div class=\"dni-plaintext\"><pre>300</pre></div></td></tr><tr><td><div class=\"dni-plaintext\"><pre>4</pre></div></td><td>小龙子</td><td><div class=\"dni-plaintext\"><pre>50</pre></div></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"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"attachments": {},
|
|
|
|
|
"cell_type": "markdown",
|
|
|
|
|
"metadata": {
|
|
|
|
|
"dotnet_interactive": {
|
|
|
|
|
"language": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "csharp"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"source": [
|
|
|
|
|
"## 使用 EF Core"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"attachments": {},
|
|
|
|
|
"cell_type": "markdown",
|
|
|
|
|
"metadata": {
|
|
|
|
|
"dotnet_interactive": {
|
|
|
|
|
"language": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "csharp"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"source": [
|
|
|
|
|
"+ 新连接,添加 --create-dbcontext 参数"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": 5,
|
|
|
|
|
"metadata": {
|
|
|
|
|
"dotnet_interactive": {
|
|
|
|
|
"language": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"vscode": {
|
|
|
|
|
"languageId": "polyglot-notebook"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"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 "
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"attachments": {},
|
|
|
|
|
"cell_type": "markdown",
|
|
|
|
|
"metadata": {
|
|
|
|
|
"dotnet_interactive": {
|
|
|
|
|
"language": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "csharp"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"source": [
|
|
|
|
|
"上面的连接操作,会执行下面的任务:\n",
|
|
|
|
|
"搭建EFCore基架,并初始化 DBContext 的实例: DemoEF\n",
|
|
|
|
|
"安装包相关Nuget包,详情见输出\n",
|
|
|
|
|
"添加新的子内核 #!sql-DemoEF"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"attachments": {},
|
|
|
|
|
"cell_type": "markdown",
|
|
|
|
|
"metadata": {
|
|
|
|
|
"dotnet_interactive": {
|
|
|
|
|
"language": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "csharp"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"source": [
|
|
|
|
|
"+ 使用EFCore连接,操作数据"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": 6,
|
|
|
|
|
"metadata": {
|
|
|
|
|
"dotnet_interactive": {
|
|
|
|
|
"language": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"vscode": {
|
|
|
|
|
"languageId": "polyglot-notebook"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"outputs": [
|
|
|
|
|
{
|
|
|
|
|
"data": {
|
|
|
|
|
"text/plain": [
|
|
|
|
|
"(4 行受到影响)"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
"metadata": {},
|
|
|
|
|
"output_type": "display_data"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"data": {
|
|
|
|
|
"text/csv": [
|
|
|
|
|
"Id,Name,Age\r\n",
|
|
|
|
|
"1,张三,20\r\n",
|
|
|
|
|
"2,李四,30\r\n",
|
|
|
|
|
"3,三丰,300\r\n",
|
|
|
|
|
"4,小龙子,50\r\n"
|
|
|
|
|
],
|
|
|
|
|
"text/html": [
|
|
|
|
|
"<table><thead><tr><td><span>Id</span></td><td><span>Name</span></td><td><span>Age</span></td></tr></thead><tbody><tr><td><div class=\"dni-plaintext\"><pre>1</pre></div></td><td>张三</td><td><div class=\"dni-plaintext\"><pre>20</pre></div></td></tr><tr><td><div class=\"dni-plaintext\"><pre>2</pre></div></td><td>李四</td><td><div class=\"dni-plaintext\"><pre>30</pre></div></td></tr><tr><td><div class=\"dni-plaintext\"><pre>3</pre></div></td><td>三丰</td><td><div class=\"dni-plaintext\"><pre>300</pre></div></td></tr><tr><td><div class=\"dni-plaintext\"><pre>4</pre></div></td><td>小龙子</td><td><div class=\"dni-plaintext\"><pre>50</pre></div></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"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"attachments": {},
|
|
|
|
|
"cell_type": "markdown",
|
|
|
|
|
"metadata": {
|
|
|
|
|
"dotnet_interactive": {
|
|
|
|
|
"language": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "csharp"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"source": [
|
|
|
|
|
"+ 程序中使用EF Core连接"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": 35,
|
|
|
|
|
"metadata": {
|
|
|
|
|
"dotnet_interactive": {
|
|
|
|
|
"language": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "csharp"
|
|
|
|
|
},
|
|
|
|
|
"vscode": {
|
|
|
|
|
"languageId": "polyglot-notebook"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"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+Test</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>20</pre></div></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+Test</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>30</pre></div></td></tr></tbody></table></div></details></td></tr><tr><td>2</td><td><details class=\"dni-treeview\"><summary><span class=\"dni-code-hint\"><code>Submission#4+Test</code></span></summary><div><table><thead><tr></tr></thead><tbody><tr><td>Id</td><td><div class=\"dni-plaintext\"><pre>3</pre></div></td></tr><tr><td>Name</td><td>三丰</td></tr><tr><td>Age</td><td><div class=\"dni-plaintext\"><pre>300</pre></div></td></tr></tbody></table></div></details></td></tr><tr><td>3</td><td><details class=\"dni-treeview\"><summary><span class=\"dni-code-hint\"><code>Submission#4+Test</code></span></summary><div><table><thead><tr></tr></thead><tbody><tr><td>Id</td><td><div class=\"dni-plaintext\"><pre>4</pre></div></td></tr><tr><td>Name</td><td>小龙子</td></tr><tr><td>Age</td><td><div class=\"dni-plaintext\"><pre>50</pre></div></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",
|
|
|
|
|
"display(t);\n",
|
|
|
|
|
"\n",
|
|
|
|
|
"FormattableString fs = $\"select * from Test;\";\n",
|
|
|
|
|
"var c = context.Database.ExecuteSql(fs);\n",
|
|
|
|
|
"display(c);"
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"metadata": {
|
|
|
|
|
"kernelspec": {
|
|
|
|
|
"display_name": ".NET (C#)",
|
|
|
|
|
"language": "C#",
|
|
|
|
|
"name": ".net-csharp"
|
|
|
|
|
},
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelInfo": {
|
|
|
|
|
"defaultKernelName": "csharp",
|
|
|
|
|
"items": [
|
|
|
|
|
{
|
|
|
|
|
"aliases": [],
|
|
|
|
|
"name": "csharp"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"nbformat": 4,
|
|
|
|
|
"nbformat_minor": 2
|
|
|
|
|
}
|