Microsoft Campus is the informal name of Microsoft’s corporate headquarters, located at One Microsoft Way in Redmond, Washington. Microsoft initially moved onto the grounds of the campus on February 26, 1986. en.wikipedia.org/wiki/Microsoft_Redmond_Campus\n\n
",
40 | "image_permalink": "http://dixinyan.tumblr.com/image/94086491678",
41 | "can_like": true,
42 | "can_reblog": true,
43 | "can_send_in_message": true,
44 | "can_reply": false,
45 | "display_avatar": true
46 | // More post info.
47 | }
48 | // More posts.
49 | ],
50 | "total_posts": 20
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Tutorial.Shared/GettingStarted/Overview.Linq.LinqToNoSql.cs:
--------------------------------------------------------------------------------
1 | namespace Tutorial.GettingStarted
2 | {
3 | using System;
4 | using System.Diagnostics;
5 | using System.Linq;
6 |
7 | using Microsoft.Azure.Documents.Client;
8 |
9 | using Newtonsoft.Json;
10 |
11 | public class Store
12 | {
13 | [JsonProperty(PropertyName = "id")]
14 | public string Id;
15 |
16 | public string Name;
17 |
18 | public Address Address;
19 | }
20 |
21 | public class Address
22 | {
23 | public string AddressType;
24 |
25 | public string AddressLine1;
26 |
27 | public Location Location;
28 |
29 | public string PostalCode;
30 |
31 | public string CountryRegionName;
32 | }
33 |
34 | public class Location
35 | {
36 | public string City;
37 |
38 | public string StateProvinceName;
39 | }
40 |
41 | internal static partial class Overview
42 | {
43 | internal static void LinqToNoSql(string key)
44 | {
45 | using (DocumentClient client = new DocumentClient(
46 | new Uri("https://dixin.documents.azure.com:443/"), key))
47 | {
48 | IOrderedQueryable source = client.CreateDocumentQuery(
49 | UriFactory.CreateDocumentCollectionUri("dixin", "Store")); // Get source.
50 | IQueryable query = from store in source
51 | where store.Address.Location.City == "Seattle"
52 | orderby store.Name
53 | select store.Name; // Define query.
54 | // Equivalent to:
55 | // IQueryable query = source
56 | // .Where(store => store.Address.CountryRegionName == "United States")
57 | // .OrderBy(store => store.Address.PostalCode)
58 | // .Select(store => store.Name);
59 | foreach (string result in query) // Execute query.
60 | {
61 | Trace.WriteLine(result);
62 | }
63 | }
64 | }
65 | }
66 | }
--------------------------------------------------------------------------------
/Tutorial.Shared/GettingStarted/Overview.Linq.LinqToNoSql.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "id": "1424",
4 | "Name": "Closeout Boutique",
5 | "Address": {
6 | "AddressType": "Main Office",
7 | "AddressLine1": "1050 Oak Street",
8 | "Location": {
9 | "City": "Seattle",
10 | "StateProvinceName": "Washington"
11 | },
12 | "PostalCode": "98104",
13 | "CountryRegionName": "United States"
14 | }
15 | }
16 | // More documents.
17 | ]
18 |
--------------------------------------------------------------------------------
/Tutorial.Shared/GettingStarted/Overview.Linq.LinqToNoSql.sql:
--------------------------------------------------------------------------------
1 | SELECT
2 | CAST(BusinessEntityID AS varchar) AS [Id],
3 | Name AS [Name],
4 | AddressType AS [Address.AddressType],
5 | AddressLine1 AS [Address.AddressLine1],
6 | City AS [Address.Location.City],
7 | StateProvinceName AS [Address.Location.StateProvinceName],
8 | PostalCode AS [Address.PostalCode],
9 | CountryRegionName AS [Address.CountryRegionName]
10 | FROM
11 | Sales.vStoreWithAddresses
12 | WHERE
13 | AddressType = N'Main Office'
--------------------------------------------------------------------------------
/Tutorial.Shared/GettingStarted/Overview.Linq.LinqToObjects.cs:
--------------------------------------------------------------------------------
1 | namespace Tutorial.GettingStarted
2 | {
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Diagnostics;
6 | using System.Linq;
7 | using System.Reflection;
8 |
9 | internal static partial class Linq
10 | {
11 | internal static void Dynamic()
12 | {
13 | IEnumerable source = new int[] { 4, 3, 2, 1, 0, -1 }; // Get source.
14 | IEnumerable query =
15 | from dynamic value in source
16 | where value.ByPass.Compiler.Check > 0
17 | orderby value.ByPass().Compiler().Check()
18 | select value & new object(); // Define query.
19 | foreach (dynamic result in query) // Execute query.
20 | {
21 | Trace.WriteLine(result);
22 | }
23 | }
24 | }
25 |
26 | internal static partial class Linq
27 | {
28 | internal static void DelegateTypesWithQueryExpression()
29 | {
30 | Assembly coreLibrary = typeof(object).Assembly;
31 | IEnumerable> delegateGroups =
32 | from type in coreLibrary.ExportedTypes
33 | where type.BaseType == typeof(MulticastDelegate)
34 | group type by type.Namespace into delegateGroup
35 | orderby delegateGroup.Count() descending, delegateGroup.Key
36 | select delegateGroup;
37 |
38 | foreach (IGrouping delegateGroup in delegateGroups) // Output.
39 | {
40 | Trace.Write(delegateGroup.Count() + " in " + delegateGroup.Key + ":");
41 | foreach (Type delegateType in delegateGroup)
42 | {
43 | Trace.Write(" " + delegateType.Name);
44 | }
45 | Trace.Write(Environment.NewLine);
46 | }
47 | }
48 | }
49 |
50 | internal static partial class Linq
51 | {
52 | internal static void DelegateTypesWithQueryMethods()
53 | {
54 | Assembly coreLibrary = typeof(object).Assembly;
55 | IEnumerable> delegateGroups = coreLibrary.ExportedTypes
56 | .Where(type => type.BaseType == typeof(MulticastDelegate))
57 | .GroupBy(type => type.Namespace)
58 | .OrderByDescending(delegateGroup => delegateGroup.Count())
59 | .ThenBy(delegateGroup => delegateGroup.Key);
60 |
61 | foreach (IGrouping delegateGroup in delegateGroups) // Output.
62 | {
63 | Trace.Write(delegateGroup.Count() + " in " + delegateGroup.Key + ":");
64 | foreach (Type delegateType in delegateGroup)
65 | {
66 | Trace.Write(" " + delegateType.Name);
67 | }
68 | Trace.Write(Environment.NewLine);
69 | }
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Tutorial.Shared/GettingStarted/Overview.Linq.LinqToXml.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Dixin's Blog
5 | https://weblogs.asp.net:443/dixin/
6 | https://weblogs.asp.net:443/dixin/
7 |
8 | EntityFramework.Functions: Code First Functions for Entity Framework
9 | https://weblogs.asp.net/dixin/entityframework.functions
10 |
11 | Mon Dec 17, 2015 06:27:56 GMT
12 | https://weblogs.asp.net/dixin/entityframework.functions
13 | .NET
14 | LINQ
15 | Entity Framework
16 | LINQ to Entities
17 | Code First
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Tutorial.Shared/GettingStarted/Overview.Linq.NetFX.cs:
--------------------------------------------------------------------------------
1 | #if NETFX
2 | namespace Tutorial.Shared.Introduction
3 | {
4 | using System.Data;
5 | using System.Data.Common;
6 | using System.Data.SqlClient;
7 | using System.Diagnostics;
8 | using System.Linq;
9 | using Tutorial.LinqToSql;
10 |
11 | internal static partial class Overview
12 | {
13 | internal static void LinqToDataSets(string connectionString)
14 | {
15 | using (DataSet dataSet = new DataSet())
16 | using (DataAdapter dataAdapter = new SqlDataAdapter(
17 | @"SELECT [Name], [ListPrice], [ProductSubcategoryID] FROM [Production].[Product]", connectionString))
18 | {
19 | dataAdapter.Fill(dataSet);
20 | EnumerableRowCollection source = dataSet.Tables[0].AsEnumerable(); // Get source.
21 | EnumerableRowCollection query =
22 | from product in source
23 | where product.Field("ProductSubcategoryID") == 1
24 | orderby product.Field("ListPrice")
25 | select product.Field("Name"); // Define query.
26 | // Equivalent to:
27 | // EnumerableRowCollection query = source
28 | // .Where(product => product.Field("ProductSubcategoryID") == 1)
29 | // .OrderBy(product => product.Field("ListPrice"))
30 | // .Select(product => product.Field("Name"));
31 | foreach (string result in query) // Execute query.
32 | {
33 | Trace.WriteLine(result);
34 | }
35 | }
36 | }
37 |
38 | internal static void LinqToSql()
39 | {
40 | using (AdventureWorks adventureWorks = new AdventureWorks())
41 | {
42 | IQueryable source = adventureWorks.Products; // Get source.
43 | IQueryable query = from product in source
44 | where product.ProductSubcategory.ProductCategory.Name == "Bikes"
45 | orderby product.ListPrice
46 | select product.Name; // Define query.
47 | // Equivalent to:
48 | // IQueryable query = source
49 | // .Where(product => product.ProductSubcategory.ProductCategory.Name == "Bikes")
50 | // .OrderBy(product => product.ListPrice)
51 | // .Select(product => product.Name);
52 | foreach (string result in query) // Execute query.
53 | {
54 | Trace.WriteLine(result);
55 | }
56 | }
57 | }
58 | }
59 | }
60 | #endif
61 |
--------------------------------------------------------------------------------
/Tutorial.Shared/LambdaCalculus/ChurchEncoding.cs:
--------------------------------------------------------------------------------
1 | namespace Tutorial.LambdaCalculus
2 | {
3 | using static ChurchBoolean;
4 |
5 | public static partial class ChurchEncoding
6 | {
7 | // System.Boolean structure to Boolean function.
8 | public static Boolean Church(this bool boolean) => boolean ? True : False;
9 |
10 | // Boolean function to System.Boolean structure.
11 | public static bool Unchurch(this Boolean boolean) => boolean(true)(false);
12 | }
13 |
14 | public static partial class ChurchEncoding
15 | {
16 | public static Numeral Church(this uint n) => n == 0U ? ChurchNumeral.Zero : Church(n - 1U).Increase();
17 |
18 | public static uint Unchurch(this Numeral numeral) => (uint)numeral(x => (uint)x + 1U)(0U);
19 |
20 | public static string Visualize(this Numeral numeral) =>
21 | (string)numeral(x => string.Concat((string)x, "*"))(string.Empty);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Tutorial.Shared/LambdaCalculus/ChurchList.cs:
--------------------------------------------------------------------------------
1 | namespace Tutorial.LambdaCalculus
2 | {
3 | using System;
4 |
5 | using static ChurchBoolean;
6 |
7 | // ListNode is the alias of Tuple>.
8 | public delegate dynamic ListNode(Boolean f);
9 |
10 | public static partial class ChurchList
11 | {
12 | // Create = value => next => (value, next)
13 | public static readonly Func, ListNode>>
14 | Create = value => next => new ListNode(ChurchTuple>.Create(value)(next));
15 |
16 | // Value = node => node.Item1()
17 | public static readonly Func, T>
18 | Value = node => new Tuple>(node).Item1();
19 |
20 | // Next = node => node.Item2()
21 | public static readonly Func, ListNode>
22 | Next = node => new Tuple>(node).Item2();
23 | }
24 |
25 | public static partial class ChurchList
26 | {
27 | // Null = False;
28 | public static readonly ListNode
29 | Null = new ListNode(False);
30 |
31 | // IsNull = node => node(value => next => _ => False)(True)
32 | public static readonly Func, Boolean>
33 | IsNull = node => node(value => next => new Func(_ => False))(True);
34 |
35 | public static readonly Func, Func>>
36 | ListNodeAt = start => index => index(node => Next(node))(start);
37 | }
38 |
39 | public static class ListNodeExtensions
40 | {
41 | public static T Value(this ListNode node) => ChurchList.Value(node);
42 |
43 | public static ListNode Next(this ListNode node) => ChurchList.Next(node);
44 |
45 | public static Boolean IsNull(this ListNode node) => ChurchList.IsNull(node);
46 |
47 | public static ListNode ListNodeAt(this ListNode start, Numeral index) => ChurchList.ListNodeAt(start)(index);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Tutorial.Shared/LambdaCalculus/ChurchNestedList.cs:
--------------------------------------------------------------------------------
1 | namespace Tutorial.LambdaCalculus
2 | {
3 | using System;
4 |
5 | using static ChurchBoolean;
6 |
7 | // ListNode2 is the alias of Tuple>>.
8 | public delegate object NestedListNode(Boolean f);
9 |
10 | public static partial class ChurchNestedList
11 | {
12 | // Null = f => True
13 | public static readonly NestedListNode
14 | Null = f => True;
15 | }
16 |
17 | public static partial class ChurchNestedList
18 | {
19 | // IsNull = node => node.Item1()
20 | public static readonly Func, Boolean>
21 | IsNull = node => new Tuple>>(node).Item1();
22 | }
23 |
24 | public static partial class ChurchNestedList
25 | {
26 | // Create = value => next => ChurchTuple.Create(False)(ChurchTuple.Create(value)(next))
27 | public static readonly Func, NestedListNode>>
28 | Create = value => next => new NestedListNode(ChurchTuple>>.Create
29 | (False)
30 | (ChurchTuple>.Create(value)(next)));
31 | }
32 |
33 | public static partial class ChurchNestedList
34 | {
35 | // Value = node => node.Item2().Item1()
36 | public static readonly Func, T>
37 | Value = node => new Tuple>>(node).Item2().Item1();
38 |
39 | // Next = node => node.Item2().Item2()
40 | public static readonly Func, NestedListNode>
41 | Next = node => new Tuple>>(node).Item2().Item2();
42 | }
43 |
44 | public static partial class ChurchNestedList
45 | {
46 | // NodeAt = start => index = index(Next)(start)
47 | public static readonly Func, Func>>
48 | NodeAt = start => index => (NestedListNode)index(node => Next((NestedListNode)node))(start);
49 | }
50 |
51 | public static partial class NestedListNodeExtensions
52 | {
53 | public static Boolean IsNull(this NestedListNode node) => ChurchNestedList.IsNull(node);
54 |
55 | public static T Value(this NestedListNode node) => ChurchNestedList.Value(node);
56 |
57 | public static NestedListNode Next(this NestedListNode node) => ChurchNestedList.Next(node);
58 |
59 | public static NestedListNode NodeAt(this NestedListNode start, Numeral index) =>
60 | ChurchNestedList.NodeAt(start)(index);
61 | }
62 | }
--------------------------------------------------------------------------------
/Tutorial.Shared/LambdaCalculus/Combinators.Bckw.cs:
--------------------------------------------------------------------------------
1 | namespace Tutorial.LambdaCalculus
2 | {
3 | using System;
4 |
5 | public static class BckwCombinators
6 | {
7 | public static readonly Func, Func, Func>>
8 | B = x => y => z => x(y(z));
9 |
10 | public static readonly Func>, Func>>
11 | C = x => y => z => x(z)(y);
12 | }
13 |
14 | public static class BckwCombinators
15 | {
16 | public static readonly Func>
17 | K = x => y => x;
18 |
19 | public static readonly Func>, Func>
20 | W = x => y => x(y)(y);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Tutorial.Shared/LambdaCalculus/Combinators.Iota.cs:
--------------------------------------------------------------------------------
1 | namespace Tutorial.LambdaCalculus
2 | {
3 | using System;
4 |
5 | using static IotaCombinator;
6 |
7 | public static partial class IotaCombinator
8 | {
9 | public static readonly Func
10 | #pragma warning disable SA1307 // Accessible fields must begin with upper-case letter
11 | #pragma warning disable SA1311 // Static readonly fields must begin with upper-case letter
12 | ι = f => f
13 | #pragma warning restore SA1311 // Static readonly fields must begin with upper-case letter
14 | #pragma warning restore SA1307 // Accessible fields must begin with upper-case letter
15 | (new Func>>(x => y => z => x(z)(y(z)))) // S
16 | (new Func>(x => y => x)); // K
17 | }
18 |
19 | public static class IotaCalculus
20 | {
21 | public static readonly Func>>
22 | S = ι(ι(ι(ι(ι))));
23 |
24 | public static readonly Func>
25 | K = ι(ι(ι(ι)));
26 |
27 | public static readonly Func
28 | I = ι(ι);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Tutorial.Shared/LambdaCalculus/Combinators.Omega.cs:
--------------------------------------------------------------------------------
1 | namespace Tutorial.LambdaCalculus
2 | {
3 | #if DEMO
4 | public delegate TResult Func(?);
5 |
6 | public delegate TResult Func(Func self);
7 | #endif
8 |
9 | public delegate TResult SelfApplicableFunc(SelfApplicableFunc self);
10 |
11 | public static class OmegaCombinators
12 | {
13 | public static readonly SelfApplicableFunc
14 | #pragma warning disable SA1307 // Accessible fields must begin with upper-case letter
15 | #pragma warning disable SA1311 // Static readonly fields must begin with upper-case letter
16 | ω = f => f(f);
17 | #pragma warning restore SA1311 // Static readonly fields must begin with upper-case letter
18 | #pragma warning restore SA1307 // Accessible fields must begin with upper-case letter
19 |
20 | public static readonly TResult
21 | Ω = ω(ω);
22 | }
23 | }
--------------------------------------------------------------------------------
/Tutorial.Shared/LambdaCalculus/Equivalence.cs:
--------------------------------------------------------------------------------
1 | namespace Tutorial.LambdaCalculus
2 | {
3 | using System;
4 |
5 | using static ChurchBoolean;
6 |
7 | public static partial class Functions
8 | {
9 | public static readonly Func>
10 | Sequence = value1 => value2 => value2;
11 | }
12 |
13 | internal static class Halting
14 | {
15 | // IsHalting = f => x => True if f halts with x; otherwise, False
16 | internal static readonly Func, Func>
17 | IsHalting = f => x => throw new NotImplementedException();
18 |
19 | // IsNotHalting = f => If(IsHalting(f)(f))(_ => Sequence(Ω)(False))(_ => True)
20 | internal static readonly Func