LINQ Reference

July 21, 2017

Find items in list that matching condition

bool lHasAccepted = ItemsList.Any(itm => itm.IsAccepted.HasValue && itm.IsAccepted.Value == true);

Filter and count items in list

int lAcceptedCount = ItemsList.Where(itm => itm.IsAccepted.HasValue && itm.IsAccepted.Value == true).Count();

Convert Type and map

return await this.dbContext.Submissions.Where(sub => sub ...

Tags: linq

Row Counts in Postgres

July 18, 2017

Here's a query that will give an estimate of the rows in all tables of a postgres database.

SELECT schemaname,relname,n_live_tup 
FROM pg_stat_user_tables 
ORDER BY n_live_tup DESC;

Setting up git

July 16, 2017

To set a default user for a git repository, first create it:

$ git init

Next, set the user

$ git config user.name "Tim Sawyer" 
$ git config user.email "user@example.co.uk"

Tags: git config

Python 3 on Mac

July 16, 2017

I'm starting to upgrade an existing Django application form python2 to python3, and also moving to develop on a mac rather than linux.

Virtual Env

In order to create a virtualenv with python 3 (and 2) in it, use the following command:

$ virtualenv -p python3 env_name

You can then ...

Grandchildren in Entity Framework Core

July 4, 2017

To select children and grandchildren when selecting in entity framework on dot net core:

lDatabaseContext.Parents.Include(p => p.Children).ThenInclude(c => c.GrandChild)

References