Skip to content

Commit e0f5592

Browse files
committed
完整数据库访问文档
1 parent 7ff53af commit e0f5592

File tree

1 file changed

+36
-19
lines changed

1 file changed

+36
-19
lines changed

Vol.Vue/src/views/document/netCoreDev.vue

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -612,29 +612,46 @@ VolElementMenuChild.vue(新增) 、VolElementMenu.vue(新增) 、Index.vue 、co
612612
<br />`,
613613
],
614614
tips: "",
615+
},
616+
{
617+
title: "Dapper访问数据库/存储过程",
618+
content: [
619+
`<div style="color:#D4D4D4;background-color:#1E1E1E;font-family:Consolas, &quot;font-size:14px;line-height:19px;white-space:pre;">
620+
&nbsp; &nbsp; &nbsp; &nbsp; public void Test()<br />
621+
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
622+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string tranNo = "T20001000100001";<br />
623+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int orderType = 1;<br />
624+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string sql = "select * from SellOrder where TranNo=@tranNo and OrderType=@orderType";<br />
625+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //与原生dapper使用方式基本一致,更多使用方法参照dapper文档<br />
626+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DBServerProvider.SqlDapper.QueryList&lt;SellOrder&gt;(sql, new { tranNo, orderType });&nbsp; &nbsp; &nbsp;&nbsp;<br />
627+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DBServerProvider.SqlDapper.QueryFirst&lt;dynamic&gt;(sql, new { tranNo, orderType });<br />
628+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DBServerProvider.SqlDapper.QueryFirst&lt;object&gt;(sql, new { tranNo, orderType });<br />
629+
<br />
630+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DBServerProvider.SqlDapper.ExecuteScalar(sql, new { tranNo, orderType });<br />
631+
<br />
632+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //调用存储过程<br />
633+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DBServerProvider.SqlDapper.ExecuteScalar("存储过程名", new {参数 },System.Data.CommandType.StoredProcedure);<br />
634+
<br />
635+
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
636+
</div>`,
637+
],
638+
tips: `还没想好`,
639+
img: "",
615640
},
616641
{
617-
title: "Memory/Redis对象",
642+
title: "使用Memory/Redis缓存",
618643
content: [
619644
`<div style="color:#D4D4D4;background-color:#1E1E1E;font-family:Consolas, &quot;font-size:14px;line-height:19px;white-space:pre;">
620-
<div style="color:#D4D4D4;background-color:#1E1E1E;font-family:Consolas, &quot;font-size:14px;line-height:19px;white-space:pre;">
621-
<br />
622-
<div>
623-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#6a9955;">//4、获取Memory/Redis对象</span>
624-
</div>
625-
<div>
626-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#6a9955;">//&nbsp;base.CacheContext&nbsp;(仅限表xxx.Serivce.cs)</span>
627-
</div>
628-
<div>
629-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#6a9955;">//&nbsp;例:SellOrderService.Instance.CacheContext</span>
630-
</div>
631-
<div>
632-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#6a9955;">//&nbsp; Core.Utilities.HttpContext.Current.GetService&lt;ICacheService&gt;();</span>
633-
</div>
634-
<div>
635-
<br />
636-
</div>
637-
</div>
645+
<p>//以SellOrderService为例,在构造方法中获取对象</p>
646+
<span style="display:none;"></span>&nbsp; &nbsp; &nbsp; &nbsp; [ActivatorUtilitiesConstructor]<br />
647+
&nbsp; &nbsp; &nbsp; &nbsp; private ICacheService _cacheService;<br />
648+
&nbsp; &nbsp; &nbsp; &nbsp; public SellOrderService(ICacheService cacheService)<br />
649+
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
650+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //默认使用的内存缓存,如果需要使用redis将appsetting.json中设置UseRedis:"true"<br />
651+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _cacheService = cacheService;<br />
652+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //HttpContext.Current.GetService&lt;ICacheService&gt;()<br />
653+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //base.CacheContext (仅限表xxx.Serivce.cs)<br />
654+
&nbsp; &nbsp; &nbsp; &nbsp; }<span style="display:none;"></span><br />
638655
</div>`,
639656
],
640657
tips: `还没想好`,

0 commit comments

Comments
 (0)