-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
101 lines (77 loc) · 3.3 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Tooling.Connector;
using Microsoft.Xrm.Sdk.Query;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
//Authenticate
string connectionString = @"AuthType=OAuth;
Username=username;
Password=password;
Url=url;
AppId=51f81489-12ee-4a9e-aaae-a2591f45987d;
RedirectUri=app://58145B91-0C36-4500-8554-080854F2AC97;";
CrmServiceClient service = new CrmServiceClient(connectionString);
//Create a contact record
//LINQ using Early Binding
using (svcContext context = new svcContext(service))
{
//Get accounts from Seattle
var accounts = from a in context.AccountSet
where a.Address1_City == "Seattle"
select a;
}
//LINQ Query - Late Binding
// using (OrganizationServiceContext context = new OrganizationServiceContext(service))
//{
// var records = from c in context.CreateQuery("contact")
// join
// a in context.CreateQuery("account")
// on c["parentcustomerid"] equals a["accountid"]
// where c["parentcustomerid"] != null
// select new
// {
// FullName = c["fullname"],
// AccountName = a["name"]
// };
// foreach (var record in records)
// {
// Console.WriteLine(record.FullName + " " + record.AccountName);
// }
//LINQ Query
//{
// // Pull contacts where city == "Redmond"
// var records = from contact in context.CreateQuery("contact")
// where contact["address1_city"].Equals("Redmond")
// select contact;
// foreach (var record in records)
// {
// Console.WriteLine(record.Attributes["fullname"].ToString() + " " + record.Attributes["address1_city"].ToString());
// }
//}
//Counting Leads
//string query = @"<fetch distinct = 'false' mapping='logical' aggregate='true'>
//<entity name='contact'>
//<attribute name='contactid' aggregate='count' alias='NumberOfContacts'/>
//</entity>
//</fetch>";
//EntityCollection collection = service.RetrieveMultiple(new FetchExpression(query));
//foreach(Entity item in collection.Entities)
//{
// Console.WriteLine(((AliasedValue)item.Attributes["NumberOfContacts"]).Value.ToString());
//}
Console.Read();
}
}
}
}