Skip to content

Commit 8b0339e

Browse files
committed
updated samples and readme
1 parent a44f065 commit 8b0339e

File tree

4 files changed

+73
-9
lines changed

4 files changed

+73
-9
lines changed

Dapper.Samples.Data/DapperSample.mdf

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

README.md

+73-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Please note that the "One-To-Many Relatioships" and "Complex Custom Handling" po
2323

2424
To run the "Basic Samples", related to the first article "Getting Started with Dapper .NET", just run
2525

26-
```dotnet run -f net48```
26+
```dotnet run -f net5.0```
2727

2828
from
2929

@@ -35,36 +35,37 @@ folder. To run advanced samples you have to move into
3535

3636
and then from here you can just run
3737

38-
```dotnet run -f net48```
38+
```dotnet run -f net5.0```
3939

4040
to run ALL samples or
4141

42-
```dotnet run -f net48 "Sample Name"```
42+
```dotnet run -f net5.0 "Sample Name"```
4343

4444
to run that specific sample. Eg:
4545

46-
```dotnet run -f net48 "Multiple Executions"```
46+
```dotnet run -f net5.0 "Multiple Executions"```
4747

4848
to run only the "Multiple Execution" sample.
4949

5050
To have a list of all advanced samples available run:
5151

52-
```dotnet run -f net48 -help```
52+
```dotnet run -f net5.0 -help```
5353

5454
## Notes
5555

5656
### .NET Version
5757

58-
Samples are done using [.NET Core 3.0](https://www.microsoft.com/net/download/windows) and [.NET Framework 4.8](https://www.microsoft.com/net/download/windows): make sure you have them installed it on your machine.
58+
Samples are done using [.NET 5.0](https://dotnet.microsoft.com/download/dotnet/5.0), and [.NET Framework 4.8](https://www.microsoft.com/net/download/windows): make sure you have them installed it on your machine
5959

6060
The project supports multiple targets:
6161

62+
* net5.0
63+
* netcoreapp3.1
6264
* net48
63-
* netcoreapp3.0
6465

65-
To execute the application targeting one specifc framework, just use the `-f` option when running the console app:
66+
To execute the application targeting one specific framework, just use the `-f` option when running the console app:
6667

67-
```dotnet run -f net48```
68+
```dotnet run -f net5.0```
6869

6970
more info on the `-f` option here:
7071

@@ -80,3 +81,66 @@ If you are looking for samples supporting older version, take a look at the prev
8081

8182
Samples also use SQL Server as database server. If you don't have a Windows machine, you can use the Docker version: [SQL Server 2017](https://www.microsoft.com/en-us/sql-server/sql-server-2017).
8283
SQL Server database file is attached automatically using the `LocalDB/MSSQLServer` instance. If you prefer to use a non-local instance, make sure you change the connection string accordingly, and attach the database file to your instance.
84+
85+
86+
### OPENJSON and 2K limit
87+
88+
In Azure SQL and SQL Server, when JSON is returned as part of a SELECT ... FOR JSON, if the resulting JSON is bigger than 2K, it will be chunked and thus it must be put back together on the client. Using SQL Server Management Studio you will not see any of this as it automatically do this for you, but if you using .NET you have to do it yourself as described here: [User FOR JSON output in a C# client app](https://docs.microsoft.com/en-us/sql/relational-databases/json/use-for-json-output-in-sql-server-and-in-client-apps-sql-server). This is actually true for other languages and not only for C#.
89+
A bit more detail on this behavior here: [SQL Server JSON result separated in multiple rows](https://stackoverflow.com/questions/41880611/sql-server-json-result-separated-in-multiple-rows/41915103#41915103).
90+
91+
The samples have been updated to show how to properly manage this behavior, as also described in this post by MVP Hasan Savran: [JSON Challenges for DEVS in SQL Server](https://h-savran.blogspot.com/2020/04/challenges-with-returning-data-as-json.html).
92+
93+
The "trick" is to wrap FOR JSON in another SELECT or assign it to a variable:
94+
95+
```sql
96+
SELECT (
97+
SELECT
98+
u.Id,
99+
u.FirstName,
100+
u.LastName,
101+
u.EMailAddress AS 'EmailAddress',
102+
(SELECT JSON_QUERY(REPLACE(REPLACE((SELECT [Tag] FROM dbo.[UserTags] t WHERE t.UserId = u.Id FOR JSON PATH), '{"Tag":', ''), '}', ''))) AS Tags,
103+
JSON_QUERY((SELECT r.[value] as [RoleName] FROM dbo.[Users] ur CROSS APPLY STRING_SPLIT(Roles, ',') AS r WHERE ur.Id = u.Id FOR JSON AUTO)) AS Roles,
104+
u.Notes,
105+
c.Id AS 'Company.Id',
106+
c.CompanyName AS 'Company.CompanyName',
107+
c.Street AS 'Company.Address.Street',
108+
c.City AS 'Company.Address.City',
109+
c.[State] AS 'Company.Address.State',
110+
c.Country AS 'Company.Address.Country',
111+
JSON_QUERY(u.CustomData, '$.Preferences') AS Preferences
112+
FROM
113+
dbo.[Users] u
114+
LEFT JOIN
115+
dbo.[Companies] c ON u.CompanyId = c.Id
116+
WHERE
117+
u.id = @id
118+
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER
119+
) as [object]
120+
```
121+
122+
## Learn More
123+
124+
If you want to learn more on how to create modern application with SQL Server and Azure SQL, the following book is for you:
125+
126+
[![Practical Azure SQL Database for Modern Developers](./book-cover.jpg)](https://www.apress.com/it/book/9781484263693)
127+
128+
### About This Book
129+
130+
Here is the expert-level, insider guidance you need on using Azure SQL Database as your back-end data store. This book highlights best practices in everything ranging from full-stack projects to mobile applications to critical, back-end APIs. The book provides instruction on accessing your data from any language and platform. And you learn how to push processing-intensive work into the database engine to be near the data and avoid undue networking traffic. Azure SQL is explained from a developer's point of view, helping you master its feature set and create applications that perform well and delight users.
131+
132+
Core to the book is showing you how Azure SQL Database provides relational and post-relational support so that any workload can be managed with easy accessibility from any platform and any language. You will learn about features ranging from lock-free tables to columnstore indexes, and about support for data formats ranging from JSON and key-values to the nodes and edges in the graph database paradigm. Reading this book prepares you to deal with almost all data management challenges, allowing you to create lean and specialized solutions having the elasticity and scalability that are needed in the modern world.
133+
134+
### What You Will Learn
135+
136+
Master Azure SQL Database in your development projects from design to the CI/CD pipeline
137+
Access your data from any programming language and platform
138+
Combine key-value, JSON, and relational data in the same database
139+
Push data-intensive compute work into the database for improved efficiency
140+
Delight your customers by detecting and improving poorly performing queries
141+
Enhance performance through features such as columnstore indexes and lock-free tables
142+
Build confidence in your mastery of Azure SQL Database's feature set
143+
144+
145+
### Who This Book Is For
146+
Developers of applications and APIs that benefit from cloud database support, developers who wish to master their tools (including Azure SQL Database, and those who want their applications to be known for speedy performance and the elegance of their code

book-cover.jpg

41.8 KB
Loading

0 commit comments

Comments
 (0)