show line numbers in conde snippets

This commit is contained in:
Marcello 2023-10-20 18:22:46 +02:00
parent 09b46d5c57
commit b308443203
82 changed files with 1249 additions and 1251 deletions

View file

@ -27,7 +27,7 @@ The `ADO.NET` classes are found in `System.Data.dll`, and are integrated with th
## Connection to DB
```cs
```cs linenums="1"
using System;
using System.Data.SqlClient; // ADO.NET Provider, installed through NuGet
@ -55,7 +55,7 @@ namespace <namespace>
### `SqlConnection`
```cs
```cs linenums="1"
using (SqlConnection connection = new SqlConnection())
{
connection.ConnectionString = connectionString.ConnectionString;
@ -70,7 +70,7 @@ using (SqlConnection connection = new SqlConnection(connectionString)) {
### [SqlCommand](https://docs.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlcommand)
```cs
```cs linenums="1"
string sql = "<sql_instruction>";
using (SqlCommand command = new SqlCommand())
@ -94,7 +94,7 @@ using (SqlCommand command = new SqlCommand())
### `SqlDataReader`
```cs
```cs linenums="1"
using (SqlDataReader cursor = command.ExecuteReader()) // object to get data from db
{
while (cursor.Read()) // get data till possible

View file

@ -2,7 +2,7 @@
## Model & Data Annotations
```cs
```cs linenums="1"
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
@ -35,7 +35,7 @@ NuGet Packages to install:
- `Microsoft.EntityFrameworkCore.Design` *or* `Microsoft.EntityFrameworkCore.<db_provider>.Design` needed for tools to work (bundled w\ tools)
- `Microsoft.EntityFrameworkCore.<db_provider>`
```cs
```cs linenums="1"
using Microsoft.EntityFrameworkCore;
namespace <Project>.Model
@ -69,14 +69,14 @@ Create & Update DB Schema if necessary.
In Package Manager Shell:
```ps1
```ps1 linenums="1"
PM> Add-Migration <migration_name>
PM> update-database [-Verbose] # use the migrations to modify the db, -Verbose to show SQL queries
```
In dotnet cli:
```ps1
```ps1 linenums="1"
dotnet tool install --global dotnet-ef # if not already installed
dotnet ef migrations add <migration_name>
@ -87,7 +87,7 @@ dotnet ef database update
### Create
```cs
```cs linenums="1"
context.Add(entity);
context.AddRange(entities);
@ -98,7 +98,7 @@ context.SaveChanges();
[Referenced Object Not Loading Fix](https://stackoverflow.com/a/5385288)
```cs
```cs linenums="1"
context.Entities.ToList();
context.Entities.Find(id);
@ -108,7 +108,7 @@ context.Entities.Include(c => c.ForeignObject).Find(id);
### Update
```cs
```cs linenums="1"
context.Entities.Update(entity);
context.UpdateRange(entities);
@ -117,7 +117,7 @@ context.SaveChanges();
### Delete
```cs
```cs linenums="1"
context.Entities.Remove(entity);
context.RemoveRange(entities);