DataConnector
LINQ クエリ
ADO.NET provider for Google Analytics > LINQ クエリ

LINQ queries demonstrate how to operate and query the Google Analytics objects wrapped in an Entity Framework data model. Listed below are some examples of LINQ queries supported by the Entity framework.

Select and Filter

Retrieve records from the Traffic table where the Country is "Japan".

C#
コードのコピー
var records = from p in context.Traffic
            where p.Country == "Japan"
            select new { p.Country, p.Sessions, p.SocialNetwork, p.Users };
Contains

Retrieve records from the Goals table where the Name property contains the substring "xamarin".

C#
コードのコピー
var records = context.Goals.Where(x => x.Name.Contains("xamarin")); 
Limit

Retrieve the first 10 records from the Goals table.

C#
コードのコピー
var records = (from p in context.Goals
            select p).Take(10); //レコードを10 件取得します。
Order by

Retrieve all records from the Goals table and sorts them in descending order based on the Name property.

C#
コードのコピー
var records = (from p in context.Goals
            orderby p.Name descending//Order Byの実装。
            select p);
 Count

Count all entities that match a given criterion. 

C#
コードのコピー
var _count = (from p in context.Goals
            select p).Count();//選択されたレコードの数に基づいてクエリをカウントします。
Group by

Group records from the Goals table based on the Value property. The groups are then ordered in descending order based on the Value.

C#
コードのコピー
var goalTable = context.Goals.AsEnumerable();
var queryGoal = from b in goalTable
                group b by b.Value into newGroup
                orderby newGroup.Key descending
                select newGroup;
Joins

Cross join between the Goals and Traffic tables.

C#
コードのコピー
var records = from b in context.Goals
            from e in context.Traffic
            select new { b, e };//クロス結合の定義。