Skip to content

Instantly share code, notes, and snippets.

View changhuixu's full-sized avatar
💭
Everyone has a happy ending. If you're not happy, it's not the end.

Changhui Xu changhuixu

💭
Everyone has a happy ending. If you're not happy, it's not the end.
View GitHub Profile
var startsWith1 = dbContext.Customers.Where(x => x.LastName.StartsWith("pe")).Select(x => x.LastName).ToList();
Logger.LogInformation(string.Join("\t", startsWith1));
// Translated SQL:
// SELECT "c"."LastName"
// FROM "Customers" AS "c"
// WHERE "c"."LastName" IS NOT NULL AND ("c"."LastName" LIKE 'pe%')
// Output: Perko petersen Perez
var startsWith2 = dbContext.Customers.Where(x => x.LastName.ToLower().StartsWith("pe")).Select(x => x.LastName).ToList();
var result = dbContext.Customers
.Where(x=> x.LastName.StartsWith("pe", StringComparison.CurrentCultureIgnoreCase))
.ToList();
// [WARN] [Microsoft.EntityFrameworkCore.Query]
// The LINQ expression 'where [x].LastName.StartsWith(__id_0, CurrentCultureIgnoreCase)'
// could not be translated and will be evaluated locally.
LIKE Operator Description
WHERE LastName LIKE 'a%' Finds values that start with "a"
WHERE LastName LIKE '%a' Finds values that end with "a"
WHERE LastName LIKE '%ab%' Finds values that have "ab" in any position
WHERE LastName LIKE '_a%' Finds values that have "a" in the second position
WHERE LastName LIKE 'a_%' Finds values that start with "a" and are at least 2 characters in length
WHERE LastName LIKE 'a__%' Finds values that start with "a" and are at least 3 characters in length
WHERE LastName LIKE 'a%e' Finds values that start with "a" and ends with "e"
public static int CalculateAge(DateTime birthday, DateTime now)
{
if (birthday == DateTime.MinValue)
{
throw new ArgumentException("Date of birth is invalid.", nameof(birthday));
}
if (birthday >= now) return 0;
var age = now.Year - birthday.Year;
public int CalculateAge(DateTime birthday)
{
var today = DateTime.Today;
var age = today.Year - birthday.Year;
if (birthday.DayOfYear > today.DayOfYear)
{
age--;
}
return age;
}
# build an image "login-e2e-cypress" from the current directory
docker build -t login-e2e-cypress .
# run the e2e tests in a container
docker run -it login-e2e-cypress -- -e username=$TESTUSERNAME,password=$TESTPASSWORD
FROM cypress/base:12.16.1
WORKDIR /e2e
# copy the test folder and related json files
COPY ./cypress ./cypress
COPY ./cypress.json .
COPY ./package.json .
COPY ./package-lock.json .
docker run -it -v /$PWD://e2e -w //e2e cypress/included:4.5.0 \
-e username=$TESTUSERNAME,password=$TESTPASSWORD
export CYPRESS_username="tomsmith"
export CYPRESS_password="SuperSecretPassword!"
export TESTUSERNAME="tomsmith";
export TESTPASSWORD="SuperSecretPassword!";