本文整理汇总了C#中XrmServiceContext类的典型用法代码示例。如果您正苦于以下问题:C# XrmServiceContext类的具体用法?C# XrmServiceContext怎么用?C# XrmServiceContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XrmServiceContext类属于命名空间,在下文中一共展示了XrmServiceContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: XrmFakedContext
public void When_doing_a_crm_linq_query_and_proxy_types_and_a_selected_attribute_returned_projected_entity_is_thesubclass()
{
var fakedContext = new XrmFakedContext();
var guid1 = Guid.NewGuid();
var guid2 = Guid.NewGuid();
fakedContext.Initialize(new List<Entity>() {
new Contact() { Id = guid1, FirstName = "Jordi" },
new Contact() { Id = guid2, FirstName = "Other" }
});
var service = fakedContext.GetFakedOrganizationService();
using (XrmServiceContext ctx = new XrmServiceContext(service))
{
var matches = (from c in ctx.CreateQuery<Contact>()
where c.FirstName.Equals("Jordi")
select new
{
FirstName = c.FirstName,
CrmRecord = c
}).ToList();
Assert.True(matches.Count == 1);
Assert.True(matches[0].FirstName.Equals("Jordi"));
Assert.IsAssignableFrom(typeof(Contact), matches[0].CrmRecord);
Assert.True(matches[0].CrmRecord.GetType() == typeof(Contact));
}
}
示例2: UpdateBaselineProjection
public void UpdateBaselineProjection(CustomBaselineProjection bp)
{
using (var ctx = new XrmServiceContext("Xrm"))
{
var bps = (from s in ctx.new_baselineprojectionsSet
where s.Id == bp.Id
select s).FirstOrDefault();
bps.new_name = bp.Name;
bps.new_Year = bp.Year;
bps.new_CA_Q1Actual = (int)bp.CA_Q1_A;
bps.new_Q1_ca = (decimal)bp.CA_Q1_P;
bps.new_CA_Q2Actual = (int)bp.CA_Q2_A;
bps.new_Q2_ca = (decimal)bp.CA_Q2_P;
bps.new_CA_Q3Actual = (int)bp.CA_Q3_A;
bps.new_Q3_ca = (decimal)bp.CA_Q3_P;
bps.new_CA_Q4Actual = (int)bp.CA_Q4_A;
bps.new_Q4_ca = (decimal)bp.CA_Q4_P;
bps.new_DB_Q1Actual = (int)bp.DB_Q1_A;
bps.new_Q1_db = (decimal)bp.DB_Q1_P;
bps.new_DB_Q2Actual = (int)bp.DB_Q2_A;
bps.new_Q2_db = (decimal)bp.DB_Q2_P;
bps.new_DB_Q3Actual = (int)bp.DB_Q3_A;
bps.new_Q3_db = (decimal)bp.DB_Q3_P;
bps.new_DB_Q4Actual = (int)bp.DB_Q4_A;
bps.new_Q4_db = (decimal)bp.DB_Q4_P;
ctx.UpdateObject(bps);
ctx.SaveChanges();
}
}
示例3: When_doing_a_crm_linq_query_with_an_equals_operator_record_is_returned
public void When_doing_a_crm_linq_query_with_an_equals_operator_record_is_returned()
{
var fakedContext = new XrmFakedContext();
var guid1 = Guid.NewGuid();
var guid2 = Guid.NewGuid();
fakedContext.Initialize(new List<Entity>() {
new Contact() { Id = guid1, FirstName = "Jordi" },
new Contact() { Id = guid2, FirstName = "Other" }
});
var service = fakedContext.GetFakedOrganizationService();
using (XrmServiceContext ctx = new XrmServiceContext(service))
{
var matches = (from c in ctx.CreateQuery<Contact>()
where c.FirstName.Equals("Jordi")
select c).ToList();
Assert.True(matches.Count == 1);
Assert.True(matches[0].FirstName.Equals("Jordi"));
matches = (from c in ctx.CreateQuery<Contact>()
where c.FirstName == "Jordi" //Using now equality operator
select c).ToList();
Assert.True(matches.Count == 1);
Assert.True(matches[0].FirstName.Equals("Jordi"));
}
}
示例4: When_doing_a_crm_linq_query_and_proxy_types_projection_must_be_applied_after_where_clause
public void When_doing_a_crm_linq_query_and_proxy_types_projection_must_be_applied_after_where_clause()
{
var fakedContext = new XrmFakedContext();
fakedContext.ProxyTypesAssembly = Assembly.GetExecutingAssembly();
var guid1 = Guid.NewGuid();
var guid2 = Guid.NewGuid();
fakedContext.Initialize(new List<Entity>() {
new Contact() { Id = guid1, FirstName = "Jordi", LastName = "Montana" },
new Contact() { Id = guid2, FirstName = "Other" }
});
var service = fakedContext.GetFakedOrganizationService();
using (XrmServiceContext ctx = new XrmServiceContext(service))
{
var matches = (from c in ctx.CreateQuery<Contact>()
where c.LastName == "Montana" //Should be able to filter by a non-selected attribute
select new
{
FirstName = c.FirstName
}).ToList();
Assert.True(matches.Count == 1);
Assert.True(matches[0].FirstName.Equals("Jordi"));
}
}
示例5: CreateXrmServiceContext
protected XrmServiceContext CreateXrmServiceContext(MergeOption? mergeOption = null)
{
//string organizationUri = ConfigurationManager.AppSettings["CRM_OrganisationUri"];
string organizationUri = "https://existornest2.api.crm4.dynamics.com/XRMServices/2011/Organization.svc";
IServiceManagement<IOrganizationService> OrganizationServiceManagement = ServiceConfigurationFactory.CreateManagement<IOrganizationService>(new Uri(organizationUri));
AuthenticationProviderType OrgAuthType = OrganizationServiceManagement.AuthenticationType;
AuthenticationCredentials authCredentials = GetCredentials(OrgAuthType);
AuthenticationCredentials tokenCredentials = OrganizationServiceManagement.Authenticate(authCredentials);
OrganizationServiceProxy organizationProxy = null;
SecurityTokenResponse responseToken = tokenCredentials.SecurityTokenResponse;
if (ConfigurationManager.AppSettings["CRM_AuthenticationType"] == "ActiveDirectory")
{
using (organizationProxy = new OrganizationServiceProxy(OrganizationServiceManagement, authCredentials.ClientCredentials))
{
organizationProxy.EnableProxyTypes();
}
}
else
{
using (organizationProxy = new OrganizationServiceProxy(OrganizationServiceManagement, responseToken))
{
organizationProxy.EnableProxyTypes();
}
}
IOrganizationService service = (IOrganizationService)organizationProxy;
var context = new XrmServiceContext(service);
if (context != null && mergeOption != null) context.MergeOption = mergeOption.Value;
return context;
}
示例6: Main
static void Main(string[] args)
{
var xrm = new XrmServiceContext("Xrm");
WriteExampleContacts(xrm);
//create a new contact called Allison Brown
var allisonBrown = new Xrm.Contact
{
FirstName = "Allison",
LastName = "Brown",
Address1_Line1 = "23 Market St.",
Address1_City = "Sammamish",
Address1_StateOrProvince = "MT",
Address1_PostalCode = "99999",
Telephone1 = "12345678",
EMailAddress1 = "[email protected]"
};
xrm.AddObject(allisonBrown);
xrm.SaveChanges();
WriteExampleContacts(xrm);
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
示例7: When_using_proxy_types_assembly_the_attribute_metadata_is_inferred_from_the_proxy_types_assembly
public static void When_using_proxy_types_assembly_the_attribute_metadata_is_inferred_from_the_proxy_types_assembly()
{
var fakedContext = new XrmFakedContext();
fakedContext.ProxyTypesAssembly = Assembly.GetExecutingAssembly();
var contact1 = new Entity("contact") { Id = Guid.NewGuid() }; contact1["fullname"] = "Contact 1"; contact1["firstname"] = "First 1";
var contact2 = new Entity("contact") { Id = Guid.NewGuid() }; contact2["fullname"] = "Contact 2"; contact2["firstname"] = "First 2";
fakedContext.Initialize(new List<Entity>() { contact1, contact2 });
var guid = Guid.NewGuid();
//Empty contecxt (no Initialize), but we should be able to query any typed entity without an entity not found exception
var service = fakedContext.GetFakedOrganizationService();
using (XrmServiceContext ctx = new XrmServiceContext(service))
{
var contact = (from c in ctx.CreateQuery<Contact>()
where c.FirstName.Equals("First 1")
select c).ToList();
Assert.True(contact.Count == 1);
}
}
示例8: GetOneAccount
public ProxyAccount GetOneAccount(Guid id)
{
CacheHelper.ClearCache();
var xrm = new XrmServiceContext("Xrm");
Account ac = xrm.AccountSet.Where(x => x.Id == id).FirstOrDefault();
return ObjectConverter.SingleConvertToProxyAccount(ac);
}
示例9: EntityViewDefinitionsGet
public List<XrmSavedQueryDefinition> EntityViewDefinitionsGet(string entityName)
{
var xrmContext = new XrmServiceContext(_organizationService);
var savedQueries = xrmContext.SavedQuerySet.Where(x => x.ReturnedTypeCode == entityName).ToList();
var list = savedQueries.Select(MapSavedQueryToDefinition).ToList();
return list;
}
示例10: EntityViewDefinitionGet
public XrmSavedQueryDefinition EntityViewDefinitionGet(Guid id)
{
var xrmService = new XrmServiceContext(_organizationService);
var query = xrmService.SavedQuerySet.Single(x => x.SavedQueryId == id);
var savedQueryDefinition = MapSavedQueryToDefinition(query);
return savedQueryDefinition;
}
示例11: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
var xrm = new XrmServiceContext("Xrm");
//grab all contacts where the email address ends in @example.com
var exampleContacts = xrm.OpportunitySet.ToList();
ContactsGridView.DataSource = exampleContacts;
ContactsGridView.DataBind();
}
示例12: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
var xrm = new XrmServiceContext("Xrm");
//grab all contacts where the email address ends in @example.com
var exampleContacts = xrm.ContactSet
.Where(c => c.EMailAddress1.EndsWith("@example.com"));
ContactsGridView.DataSource = exampleContacts;
ContactsGridView.DataBind();
}
示例13: WriteExampleContacts
/// <summary>
/// Grab all contacts where the email address ends in @example.com
/// </summary>
private static void WriteExampleContacts(XrmServiceContext xrm)
{
var exampleContacts = xrm.ContactSet
.Where(c => c.EMailAddress1.EndsWith("@example.com"));
//write the example Contacts
foreach (var contact in exampleContacts)
{
Console.WriteLine(contact.FullName);
}
}
示例14: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
var xrm = new XrmServiceContext("Xrm");
//grab all contacts where the email address ends in @example.com
var opps = xrm.OpportunitySet.ToList();
this.OpportunityDropdown.DataSource = opps;
this.OpportunityDropdown.DataBind();
}
}
示例15: When_calling_context_add_and_save_changes_entity_is_added_to_the_faked_context
public void When_calling_context_add_and_save_changes_entity_is_added_to_the_faked_context()
{
var context = new XrmFakedContext();
var service = context.GetFakedOrganizationService();
using(var ctx = new XrmServiceContext(service))
{
ctx.AddObject(new Account() { Name = "Test account" });
ctx.SaveChanges();
var account = ctx.CreateQuery<Account>()
.ToList()
.FirstOrDefault();
Assert.Equal("Test account", account.Name);
}
}