//QueryExpression条件查询 var query = new QueryExpression("new_ord_shipment"); query.ColumnSet.AddColumns("new_ord_shipmentid", "new_contract_id", "new_userprofile_id", "new_office_id", "new_ord_sales_id", "new_finalaccount_id", "new_selltype"); query.Criteria.AddCondition("new_name", ConditionOperator.Equal, ********);); //连接表1 LinkEntity linkEntity1 = new LinkEntity("new_ord_shipment", "new_srv_userprofile", "new_userprofile_id", "new_srv_userprofileid", JoinOperator.LeftOuter); linkEntity1.EntityAlias = "a"; linkEntity1.Columns = new ColumnSet("new_productmodel_id"); linkEntity1.LinkCriteria.AddCondition("statecode", ConditionOperator.Equal, 0); query.LinkEntities.Add(linkEntity1); //连接表2 LinkEntity linkEntity2 = new LinkEntity("new_ord_shipment", "businessunit", "new_office_id", "businessunitid", JoinOperator.LeftOuter); linkEntity2.EntityAlias = "b"; linkEntity2.Columns = new ColumnSet("parentbusinessunitid"); query.LinkEntities.Add(linkEntity2); //连接表3 LinkEntity linkEntity3 = new LinkEntity("new_ord_shipment", "new_ord_sales", "new_ord_sales_id", "new_ord_salesid", JoinOperator.LeftOuter); linkEntity3.EntityAlias = "c"; linkEntity3.Columns = new ColumnSet("new_tel", "new_dealers_id"); linkEntity3.LinkCriteria.AddCondition("statecode", ConditionOperator.Equal, 0); query.LinkEntities.Add(linkEntity3); //查询 var ec = OrganizationServiceAdmin.RetrieveMultiple(query); var createEntity = new Entity("new_insurance_sell");//实体对象 //如果结果不为空 if (ec != null && ec.Entities != null && ec.Entities.Count > 0) { var item = ec.Entities[0]; //主实体的主键字段类型是Guid createEntity["new_ord_shipmentid"] = new EntityReference("new_ord_shipment",item.GetAttributeValue<Guid>("new_ord_shipmentid")); if (item.Contains("new_selltype")) { createEntity["new_saletype"] = item.GetAttributeValue<OptionSetValue>("new_selltype"); } if (item.Contains("new_contract_id")) { createEntity["new_contract_id"] = item.GetAttributeValue<EntityReference>("new_contract_id"); } // 连接的实体查询出来的是匿名字段(别名字段)需要用AliasedValue类型接收,接收之后的Value值为本来的类型,这个new_productmodel_id为lookup类型,所以它类型为EntityReference //或者这里也可以直接用GetAliasAttributeValue<EntityReference>来接收查到的值, //比如这里也可用item.GetAliasAttributeValue<EntityReference>("a.new_productmodel_id") if (item.Contains("a.new_productmodel_id")) { createEntity["new_productmodel_id"] = item.GetAttributeValue<AliasedValue>("a.new_productmodel_id").Value; } if (item.Contains("c.new_dealers_id")) { createEntity["new_discustomer"] = item.GetAliasAttributeValue<EntityReference>("c.new_dealers_id"); } } OrganizationService.Create(createEntity);//执行创建实体
//直接查询实体 var entity = OrganizationService.Retrieve("new_ord_shipment", new Guid("0A8FEDFB-B934-E911-A12C-000C2921A033"), new ColumnSet(true)); var old_new_price = entity.GetAttributeValue<dynamic>("new_price");