Posts Tagged ‘LINQ’

Using aggregate functions SUM and COUNT together in one LINQ query

Today, I needed to use more then one aggregate function together in one LINQ query and I did a brief search in the internet. I found some sites that can be useful but not really a sample for my case. One of the nice web sites with samples is 101 LINQ Samples. It contains samples [...]

Implement SQL IN and NOT IN operators and sub-queries using LINQ to SQL

SQL IN and NOT IN operators with a combination with sub-queries can be really useful in some cases. An example of this is below. All queries in this post don’t contain real tables.

1: select *

2: from table1 t1

3: where t1.id in (

4: [...]

Concatenate nvarchar field and ntext field. Push LINQ to convert ntext to nvarchar.

Let’s assume that we have a table like

This table contains a field name of type nvarchar(50) and a field description of type ntext. Assume we need name and description field values concatenated in one field. Using LINQ we can write a query like that.

1: var result = (from r in [...]