public static CrmQuery Select( ColumnSet in_columns ) { #endif QueryExpression query = new QueryExpression(); query.ColumnSet = in_columns; CrmQuery dsl = new CrmQuery(); dsl.m_query = query; return dsl; }
public void TestSingleFilter() { QueryBase query = CrmQuery .Select() .From("mydynamic") .Where("mydynamic", "prop1", ConditionOperator.Equal, new object[] { "foo" }).Query; EntityCollection bec = m_service.RetrieveMultiple(query); Fest.AssertTrue(bec.Entities.Count > 0, "found more than zero entities"); }
public void TestLinks() { QueryBase query = CrmQuery .Select() .From("subject") .Join("subject", "subjectid", "subject", "parentsubject") .Where("subject", "title", ConditionOperator.Equal, new object[] { "child" }).Query; EntityCollection bec = m_service.RetrieveMultiple(query); Fest.AssertTrue(bec.Entities.Count > 0, "found more than zero entities"); }
public void TestMultipleFilters() { QueryBase query = CrmQuery .Select() .From("contact") .Where("contact", "address1_name", ConditionOperator.Equal, new object[] { "Dan" }) .Where("contact", "address1_city", ConditionOperator.Equal, new object[] { "Bethesda" }).Query; EntityCollection bec = m_service.RetrieveMultiple(query); Fest.AssertTrue(bec.Entities.Count > 0, "found more than zero entities"); }
public void TestLinkPosition() { QueryExpression query = CrmQuery .Select(new AllColumns()) .From("new_dynamicformfield") .Join("new_dynamicformfield", "new_formfieldid", "new_dynamicform", "new_dynamicformid") .Where("new_dynamicform", "new_name", ConditionOperator.Equal, new string[] { "registry" }).Query; Fest.AssertTrue(query.EntityName == "new_dynamicformfield", "Entity name not set"); Fest.AssertTrue((( LinkEntity )query.LinkEntities[0]).LinkFromEntityName == query.EntityName, "LinkEntity added in incorrect position"); }
void uploadBtn_Click(object sender, EventArgs e) { byte[] fileData = null; if (fileUpload != null && fileUpload.PostedFile.ContentLength > 0) { DeleteExistingImage(); using (var binaryReader = new BinaryReader(fileUpload.FileContent)) fileData = binaryReader.ReadBytes(fileUpload.PostedFile.ContentLength); //---------------------- //CrmQuery crmQuery = new CrmQuery(Person.EntityLogicalName); //crmQuery.AddSimpleCondition(Person.AttributeNames.PersonID, LoggedInUserId.Value.ToString()); //CoreContact externalAgent = WebControlUtility.CrmData.RetrieveMultiple<Person>(crmQuery).First<Person>(); //externalAgent.Attributes["entityimage"] = fileData; //WebControlUtility.CrmData.Update(externalAgent); OrganizationServiceContext context = new OrganizationServiceContext(WebControlUtility.CrmData.Connection.OrganizationService); Entity contact = context.CreateQuery(Person.EntityLogicalName).Where(c => c.GetAttributeValue <Guid>(Person.AttributeNames.PersonID) .Equals(LoggedInUserId.Value.ToString())).First <Entity>(); contact.Attributes["entityimage"] = fileData; context.UpdateObject(contact); try { context.SaveChanges(); } catch (Exception ex) { InvalidFileTypesErrorMessage = "Invalid File, Retty with a valid picture file: " + ex.Message; } //--------------------------- WebControlUtility.CrmData.AddAttachmentToEntity(fileUpload.FileContent, fileUpload.PostedFile.ContentLength, fileUpload.PostedFile.ContentType, "prospectimageupload_" + fileUpload.FileName, "", Person.EntityLogicalName, LoggedInUserId.Value); } CrmQuery query = new CrmQuery(Person.EntityLogicalName); query.Attributes = new List <string>() { "entityimage" }; query.AddSimpleCondition(Person.AttributeNames.PersonID, LoggedInUserId.Value.ToString()); var attachments = WebControlUtility.CrmData.RetrieveMultiple <Person>(query).ToList(); byte[] imageBytes = attachments[0].GetAttributeValue <byte[]>("entityimage"); string imgB = Convert.ToBase64String(imageBytes, 0, imageBytes.Length); img.ImageUrl = "data:image/png;base64," + imgB; ShowImage(); // this.Context.Response.Redirect(RedirectUrl); }
public void TestLinkPosition2() { // two joins, both linking from root entity to separate child entities. QueryExpression query = CrmQuery .Select(new AllColumns()) .From("rootentity") .Join("rootentity", "id", "childentity", "parentid") .Join("rootentity", "id", "childentity2", "parentid").Query; Fest.AssertTrue(query.EntityName == "rootentity", "Entity name not set"); Fest.AssertTrue((( LinkEntity )query.LinkEntities[0]).LinkFromEntityName == query.EntityName, "LinkEntity added in incorrect position"); Fest.AssertTrue((( LinkEntity )query.LinkEntities[1]).LinkFromEntityName == query.EntityName, "LinkEntity added in incorrect position"); }
public void TestLinkPosition3() { // two joins, one linked from root, second linked from first QueryExpression query = CrmQuery .Select(new AllColumns()) .From("rootentity") .Join("rootentity", "id", "childentity", "parentid") .Join("childentity", "id", "childentity2", "parentid").Query; LinkEntity le1 = ( LinkEntity )query.LinkEntities[0]; LinkEntity le2 = ( LinkEntity )le1.LinkEntities[0]; Fest.AssertTrue(query.EntityName == "rootentity", "Entity name not set"); Fest.AssertTrue(le1.LinkFromEntityName == query.EntityName, "LinkEntity added in incorrect position"); Fest.AssertTrue(le2.LinkFromEntityName == le1.LinkToEntityName, "LinkEntity added in incorrect position"); }
private void ShowImage() { CrmQuery qe = new CrmQuery("systemform"); qe.AddSimpleCondition("type", "2"); //main form qe.AddSimpleCondition("objecttypecode", Person.EntityLogicalName.ToLower()); qe.Attributes = new List <string>() { "formxml" }; var allSysforms = WebControlUtility.CrmData.RetrieveMultiple <SystemForm>(qe); SystemForm ImageAttributeDemoMainForm = allSysforms.First <SystemForm>(); XDocument ImageAttributeDemoMainFormXml = XDocument.Parse(ImageAttributeDemoMainForm.formxml); if (ImageAttributeDemoMainFormXml.Root.Attribute("showImage").Value == "true") { ImageAttributeDemoMainFormXml.Root.SetAttributeValue("showImage", false); } else { ImageAttributeDemoMainFormXml.Root.SetAttributeValue("showImage", true); //Updating the entity form definition } ImageAttributeDemoMainForm.formxml = ImageAttributeDemoMainFormXml.ToString(); WebControlUtility.CrmData.Update(ImageAttributeDemoMainForm); OrganizationServiceContext context = new OrganizationServiceContext(WebControlUtility.CrmData.Connection.OrganizationService); PublishXmlRequest pxReq1 = new PublishXmlRequest { ParameterXml = String.Format(@" <importexportxml> <entities> <entity>{0}</entity> </entities> </importexportxml>", Person.EntityLogicalName.ToLower()) }; context.Execute(pxReq1); }
public void TestConditionPosition() { // two joins, one linked from root, second linked from first // putting a where clause in between. QueryExpression query = CrmQuery .Select(new AllColumns()) .From("rootentity") .Join("rootentity", "id", "childentity", "parentid") .Where("childentity", "myproperty", ConditionOperator.Equal, new object[] { "val1" }) .Join("childentity", "id", "childentity2", "parentid").Query; LinkEntity le1 = ( LinkEntity )query.LinkEntities[0]; LinkEntity le2 = ( LinkEntity )le1.LinkEntities[0]; // TODO: this brings up an interesting issue - where do we want to put criteria when adding via 'Where()'. // Currently they end up getting a new Filter under LinkCriteria rather than added to the existing FilterExpression. ConditionExpression ce = ( ConditionExpression )(( FilterExpression )le1.LinkCriteria.Filters[0]).Conditions[0]; Fest.AssertTrue(query.EntityName == "rootentity", "Entity name not set"); Fest.AssertTrue(le1.LinkFromEntityName == query.EntityName, "LinkEntity added in incorrect position"); Fest.AssertTrue(le2.LinkFromEntityName == le1.LinkToEntityName, "LinkEntity added in incorrect position"); Fest.AssertTrue(ce.AttributeName == "myproperty", "ConditionExpression added in incorrect position"); }
public CrmQuery Where( string in_entity, string in_field, ConditionOperator in_operator, object[] in_values ) { FilterExpression filterExpression = CrmQuery.WhereExpression( in_field, in_operator, in_values ); return Where( in_entity, filterExpression ); }