First statement concatenates schema
with table name
while the second statement separates schema name
and table name
.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var statement = | |
""" | |
SELECT * | |
FROM dbo.Customers | |
WHERE ContactTypeIdentifier = 9 | |
"""; | |
using var context = new Context(); | |
var list = context.Customers.FromSqlRaw(statement) | |
.Include(c => c.Contact) | |
.ToList(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE dbo.Taxpayers (Id INT IDENTITY PRIMARY KEY, | |
FullName NVARCHAR(100) NOT NULL, | |
Email NVARCHAR(100) NOT NULL, | |
Social VARCHAR(9) MASKED WITH (FUNCTION = 'partial(0,"XXXXX",4)') NOT NULL, | |
CreditCardNumber VARCHAR(16) MASKED WITH (FUNCTION = 'partial(0, "XXXX-XXXX-X-", 4)') NULL, | |
BirthDate DATE NOT NULL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @BrokenTable TABLE (ID INT NOT NULL); | |
INSERT INTO @BrokenTable VALUES (1); | |
INSERT INTO @BrokenTable VALUES (3); | |
INSERT INTO @BrokenTable VALUES (5); | |
INSERT INTO @BrokenTable VALUES (7); | |
INSERT INTO @BrokenTable VALUES (9); | |
WITH CTE | |
AS (SELECT 1 AS Number | |
UNION ALL | |
SELECT Number + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Version FrameworkRuntimeVersion() | |
{ | |
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly; | |
var path = assembly.Location.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries); | |
var index = Array.IndexOf(path, "Microsoft.NETCore.App"); | |
return new Version((index > 0 && index < path.Length - 2 ? path[index + 1] : null)!); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main(string[] args) | |
{ | |
int current = 20240403; | |
int birthDate = 19000924; | |
Console.WriteLine((current - birthDate).ToString()[..^4]); | |
Console.WriteLine((current - birthDate).ToString().RemoveLastCharacters()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @sql NVARCHAR(MAX); | |
SELECT @sql | |
= ( SELECT ' UNION ALL | |
SELECT ' + +QUOTENAME(name, '''') | |
+ ' as DatabaseName, | |
s.name COLLATE DATABASE_DEFAULT | |
AS SchemaName, | |
t.name COLLATE DATABASE_DEFAULT as TableName | |
FROM ' + QUOTENAME(name) + '.sys.tables t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ISample | |
{ | |
public void AcceptCallMethod(); | |
void CallerMethod() { } | |
} | |
public class Sample : ISample | |
{ | |
void ISample.AcceptCallMethod() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Text.RegularExpressions; | |
public static class StringExtensions | |
{ | |
// remove double spaces | |
public static string RemoveExtraSpaces(this string sender, bool trimEnd = false) | |
{ | |
const RegexOptions options = RegexOptions.None; | |
var regex = new Regex("[ ]{2,}", options); | |
var result = regex.Replace(sender, " "); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string GetNetCoreVersion() | |
{ | |
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly; | |
var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries); | |
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App"); | |
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2) | |
return assemblyPath[netCoreAppIndex + 1]; | |
return null; | |
} |
NewerOlder