Skip to content

Commit 092bdec

Browse files
chore(grid):sample project with dapper (#129)
* chore(grid):sample project with dapper * Update grid/dapper/README.md Co-authored-by: Dimo Dimov <961014+dimodi@users.noreply.github.com> Co-authored-by: Dimo Dimov <961014+dimodi@users.noreply.github.com>
1 parent dbfee4f commit 092bdec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2320
-0
lines changed

grid/dapper/.gitignore

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
## Ignore Visual Studio temporary files, build results, and
2+
## files generated by popular Visual Studio add-ons.
3+
# User-specific files
4+
*.suo
5+
*.user
6+
*.userosscache
7+
*.sln.docstates
8+
# User-specific files (MonoDevelop/Xamarin Studio)
9+
*.userprefs
10+
# Build results
11+
[Dd]ebug/
12+
[Dd]ebugPublic/
13+
[Rr]elease/
14+
[Rr]eleases/
15+
x64/
16+
x86/
17+
bld/
18+
[Bb]in/
19+
[Oo]bj/
20+
[Ll]og/
21+
# Visual Studio 2015 cache/options directory
22+
.vs/
23+
# Uncomment if you have tasks that create the project's static files in wwwroot
24+
#wwwroot/
25+
# MSTest test Results
26+
[Tt]est[Rr]esult*/
27+
[Bb]uild[Ll]og.*
28+
# NUNIT
29+
*.VisualState.xml
30+
TestResult.xml
31+
# Build Results of an ATL Project
32+
[Dd]ebugPS/
33+
[Rr]eleasePS/
34+
dlldata.c
35+
# DNX
36+
project.lock.json
37+
project.fragment.lock.json
38+
artifacts/
39+
*_i.c
40+
*_p.c
41+
*_i.h
42+
*.ilk
43+
*.meta
44+
*.obj
45+
*.pch
46+
*.pdb
47+
*.pgc
48+
*.pgd
49+
*.rsp
50+
*.sbr
51+
*.tlb
52+
*.tli
53+
*.tlh
54+
*.tmp
55+
*.tmp_proj
56+
*.log
57+
*.vspscc
58+
*.vssscc
59+
.builds
60+
*.pidb
61+
*.svclog
62+
*.scc
63+
# Chutzpah Test files
64+
_Chutzpah*
65+
# Visual C++ cache files
66+
ipch/
67+
*.aps
68+
*.ncb
69+
*.opendb
70+
*.opensdf
71+
*.sdf
72+
*.cachefile
73+
*.VC.db
74+
*.VC.VC.opendb
75+
# Visual Studio profiler
76+
*.psess
77+
*.vsp
78+
*.vspx
79+
*.sap
80+
# TFS 2012 Local Workspace
81+
$tf/
82+
# Guidance Automation Toolkit
83+
*.gpState
84+
# ReSharper is a .NET coding add-in
85+
_ReSharper*/
86+
*.[Rr]e[Ss]harper
87+
*.DotSettings.user
88+
# JustCode is a .NET coding add-in
89+
.JustCode
90+
# TeamCity is a build add-in
91+
_TeamCity*
92+
# DotCover is a Code Coverage Tool
93+
*.dotCover
94+
# NCrunch
95+
_NCrunch_*
96+
.*crunch*.local.xml
97+
nCrunchTemp_*
98+
# MightyMoose
99+
*.mm.*
100+
AutoTest.Net/
101+
# Web workbench (sass)
102+
.sass-cache/
103+
# Installshield output folder
104+
[Ee]xpress/
105+
# DocProject is a documentation generator add-in
106+
DocProject/buildhelp/
107+
DocProject/Help/*.HxT
108+
DocProject/Help/*.HxC
109+
DocProject/Help/*.hhc
110+
DocProject/Help/*.hhk
111+
DocProject/Help/*.hhp
112+
DocProject/Help/Html2
113+
DocProject/Help/html
114+
# Click-Once directory
115+
publish/
116+
# Publish Web Output
117+
*.[Pp]ublish.xml
118+
*.azurePubxml
119+
# TODO: Comment the next line if you want to checkin your web deploy settings
120+
# but database connection strings (with potential passwords) will be unencrypted
121+
#*.pubxml
122+
*.publishproj
123+
# Microsoft Azure Web App publish settings. Comment the next line if you want to
124+
# checkin your Azure Web App publish settings, but sensitive information contained
125+
# in these scripts will be unencrypted
126+
PublishScripts/
127+
# NuGet Packages
128+
*.nupkg
129+
# The packages folder can be ignored because of Package Restore
130+
**/packages/*
131+
# except build/, which is used as an MSBuild target.
132+
!**/packages/build/
133+
# Uncomment if necessary however generally it will be regenerated when needed
134+
#!**/packages/repositories.config
135+
# NuGet v3's project.json files produces more ignoreable files
136+
*.nuget.props
137+
*.nuget.targets
138+
# Microsoft Azure Build Output
139+
csx/
140+
*.build.csdef
141+
# Microsoft Azure Emulator
142+
ecf/
143+
rcf/
144+
# Windows Store app package directories and files
145+
AppPackages/
146+
BundleArtifacts/
147+
Package.StoreAssociation.xml
148+
_pkginfo.txt
149+
# Visual Studio cache files
150+
# files ending in .cache can be ignored
151+
*.[Cc]ache
152+
# but keep track of directories ending in .cache
153+
!*.[Cc]ache/
154+
# Others
155+
ClientBin/
156+
~$*
157+
*~
158+
*.dbmdl
159+
*.dbproj.schemaview
160+
*.jfm
161+
*.pfx
162+
*.publishsettings
163+
node_modules/
164+
orleans.codegen.cs
165+
# Since there are multiple workflows, uncomment next line to ignore bower_components
166+
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
167+
#bower_components/
168+
# RIA/Silverlight projects
169+
Generated_Code/
170+
# Backup & report files from converting an old project file
171+
# to a newer Visual Studio version. Backup files are not needed,
172+
# because we have git ;-)
173+
_UpgradeReport_Files/
174+
Backup*/
175+
UpgradeLog*.XML
176+
UpgradeLog*.htm
177+
# SQL Server files
178+
*.mdf
179+
*.ldf
180+
# Business Intelligence projects
181+
*.rdl.data
182+
*.bim.layout
183+
*.bim_*.settings
184+
# Microsoft Fakes
185+
FakesAssemblies/
186+
# GhostDoc plugin setting file
187+
*.GhostDoc.xml
188+
# Node.js Tools for Visual Studio
189+
.ntvs_analysis.dat
190+
# Visual Studio 6 build log
191+
*.plg
192+
# Visual Studio 6 workspace options file
193+
*.opt
194+
# Visual Studio LightSwitch build output
195+
**/*.HTMLClient/GeneratedArtifacts
196+
**/*.DesktopClient/GeneratedArtifacts
197+
**/*.DesktopClient/ModelManifest.xml
198+
**/*.Server/GeneratedArtifacts
199+
**/*.Server/ModelManifest.xml
200+
_Pvt_Extensions
201+
# Paket dependency manager
202+
.paket/paket.exe
203+
paket-files/
204+
# FAKE - F# Make
205+
.fake/
206+
# JetBrains Rider
207+
.idea/
208+
*.sln.iml
209+
# CodeRush
210+
.cr/
211+
# Python Tools for Visual Studio (PTVS)
212+
__pycache__/
213+
*.pyc
214+
# CUSTOM
215+
appsettings.json
216+
DB/
217+
CornixLoggerFunctions20210416162430 - Zip Deploy.pubxml

grid/dapper/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# TelerikBlazorGrid-Dapper
2+
3+
Demonstrates a Telerik Grid in Blazor, using the OnRead event along with Dapper and Dapper.SqlBuilder, to generate your SQL queries on the fly supporting most aspects of Telerik Grid.
4+
Telerik Grid works nicely with Entity Framework, you can use `.ToDataSourceResultAsync()` and everything for sorting etc happens on the database. If you are using Dapper you can use that, however as Dapper doesn't return an IQueryable, you will be fetching the entire dataset and then filtering, paging and sorting in code, rather than on your database.
5+
6+
**Special thanks to @pingu2k4 for the sample.**
7+
8+
## Features
9+
- [x] Paging
10+
- [x] Sorting
11+
- [x] Filtering
12+
- [ ] Grouping
13+
- [ ] Aggregate Information
14+
15+
## Setup
16+
1. Open the project, right click on the `TelerikBlazorGrid.SqlDB.sqlproj` file and then `Import` -> `Script(*.sql)`
17+
2. Click **Next** on the window that popped
18+
3. After that, choose **Multiple files** and click **Browse...**
19+
![third step screenshot](images/third-step.png)
20+
4. Select the **Scripts** folder in the project and click **Finish**
21+
![fourth step screenshot](images/fourth-step.png)
22+
5. Right click again on the `TelerikBlazorGrid.SqlDB.sqlproj` file and then `Publish...`
23+
6. Click **Edit** in the popped window
24+
7. Type **Server Name** and **User Name** from your SQL Server
25+
![seventh step screenshot](images/seventh-step.png)
26+
8. Copy the generated connection string and close the window
27+
![eighth step screenshot](images/eighth-step.png)
28+
9. Paste the connection string in the `appsettings.Development.json` file and you are ready to go
29+
30+
## The Magic
31+
If you are looking for where the majority of the code that performs this is held, take a look at `TelerikBlazorGrid_Dapper.DataAccess.Extensions.SqlBuilderExtensions`. We build up 2 sql templates, one for the query to get our data, and another to query the total count.
32+
By default, you should only need to provide this method the table (or view) name you wish to query. However there are instances where you wish to query a different table or view for both the data selection and the count - For example where you have a view containing a join as the count will become inaccurate, counting all the duplicate rows.
33+
You may also specify a different default sort field and direction.
34+
35+
## The Result
36+
This picture shows the end result. A table with full sort, filter and paging functionality - Using OnRead through dapper, and passing the handling of all the Grid functionalities over to the database.
37+
![dapper grid](images/dapper-grid.png)
38+
39+
## Disclaimer
40+
Integration with Dapper is not subject to technical support by Progress.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
</Found>
5+
<NotFound>
6+
<LayoutView Layout="@typeof(MainLayout)">
7+
<p>Sorry, there's nothing at this address.</p>
8+
</LayoutView>
9+
</NotFound>
10+
</Router>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@page
2+
@model TelerikBlazorGrid_Dapper.Blazor.Pages.ErrorModel
3+
4+
<!DOCTYPE html>
5+
<html>
6+
7+
<head>
8+
<meta charset="utf-8" />
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
10+
<title>Error</title>
11+
<link href="~/css/bootstrap/bootstrap.min.css" rel="stylesheet" />
12+
<link href="~/css/app.css" rel="stylesheet" />
13+
</head>
14+
15+
<body>
16+
<div class="main">
17+
<div class="content px-4">
18+
<h1 class="text-danger">Error.</h1>
19+
<h2 class="text-danger">An error occurred while processing your request.</h2>
20+
21+
@if (Model.ShowRequestId)
22+
{
23+
<p>
24+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
25+
</p>
26+
}
27+
28+
<h3>Development Mode</h3>
29+
<p>
30+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
31+
</p>
32+
<p>
33+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
34+
It can result in displaying sensitive information from exceptions to end users.
35+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
36+
and restarting the app.
37+
</p>
38+
</div>
39+
</div>
40+
</body>
41+
42+
</html>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
using Microsoft.Extensions.Logging;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Diagnostics;
7+
using System.Linq;
8+
using System.Threading.Tasks;
9+
10+
namespace TelerikBlazorGrid_Dapper.Blazor.Pages
11+
{
12+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
13+
[IgnoreAntiforgeryToken]
14+
public class ErrorModel : PageModel
15+
{
16+
public string RequestId { get; set; }
17+
18+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
19+
20+
private readonly ILogger<ErrorModel> _logger;
21+
22+
public ErrorModel(ILogger<ErrorModel> logger)
23+
{
24+
_logger = logger;
25+
}
26+
27+
public void OnGet()
28+
{
29+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)