码迷,mamicode.com
首页 > 其他好文 > 详细

Dynamic对实体进行增删改查

时间:2020-04-29 18:32:08      阅读:66      评论:0      收藏:0      [点我收藏+]

标签:org   rom   except   span   distinct   mic   opera   esc   tab   

1.查询

(1)

public PersisitBroker broker;
public SyncAccountCommand()
{
   broker = new PersisitBroker("CRM");
}

string sql = string.Format(@"SELECT new_userid, isnull(new_name, ‘ ‘) AS new_name, new_email
                                             , new_userrole, isnull(new_phone, ‘ ‘) AS new_phone, statecode
                                         FROM new_user
                                         WHERE new_email IS NOT NULL
                                         AND new_userrole IS NOT NULL");
DataTable dt = this.broker.Query(sql);

(2)

QueryExpression qe = new QueryExpression("new_yaoorder");
qe.ColumnSet.AllColumns = true;
qe.Criteria.AddCondition("new_yaoorderid", ConditionOperator.Equal, currentEntity.GetAttributeValue<EntityReference>("new_yaoorderid").Id);
qe.NoLock = true;
qe.TopCount = 1;
var ec = orgSvc.RetrieveMultiple(qe);

//单价金额
ec.Entities[0]["new_sumamount"] = (decimal)999;
//优惠金额
decimal new_sumamount = decimal.Parse(ec.Entities[0]["new_sumamount"].ToString());
//应付金额 = 单价金额 - 优惠金额
ec.Entities[0]["new_paymentamount"] = decimal.Parse(ec.Entities[0]["new_sumamount"].ToString()) - new_sumamount;
try
{
orgSvc.Update(ec[0]);
}
catch (Exception ex)
{

throw new InvalidPluginExecutionException(ex.ToString());
}

 (3)

QueryExpression queryEmail = new QueryExpression("new_tmpl_mail");
queryEmail.ColumnSet = new ColumnSet(new string[] { "new_topic", "new_memo" });
queryEmail.Criteria.AddCondition("new_type", ConditionOperator.Equal, 1);
queryEmail.Criteria.AddCondition("new_code", ConditionOperator.Equal, "E-mail template");
queryEmail.AddOrder("createdon", OrderType.Descending);
EntityCollection emailEnt = OrganizationService.RetrieveMultiple(queryEmail);
if (emailEnt != null && emailEnt.Entities != null && emailEnt.Entities.Count > 0)
{
Entity entEmail = emailEnt[0];
var new_topic = entEmail.GetAttributeValue<string>("new_topic");
var subject = string.Format(new_topic, model.UserName);
var new_memo = entEmail.GetAttributeValue<string>("new_memo");

}

(4)

FetchExpression fetchXml = new FetchExpression(string.Format(@"<fetch version=‘1.0‘ output-format=‘xml-platform‘ mapping=‘logical‘ distinct=‘false‘>
<entity name=‘new_systemparameter‘>
<attribute name=‘new_systemparameterid‘ />
<attribute name=‘new_value‘ />
<filter type=‘and‘>
<condition attribute=‘statecode‘ operator=‘eq‘ value=‘0‘ />
<condition attribute=‘new_name‘ operator=‘eq‘ value=‘{0}‘ />
</filter>
</entity>
</fetch>", name));
EntityCollection ec = OrganizationService.RetrieveMultiple(fetchXml);
if (ec != null && ec.Entities != null && ec.Entities.Count > 0)
{
value = ec.Entities[0]["new_value"].ToString();
}

2.增加

(1)

this.OrganizationService.Create(entity);

3.修改

(1)

          string updateSql = string.Format(@"
          update new_user
          set new_issend={0}
          where new_userId=‘{1}‘", 0, model.OutterUserId);
          broker.Execute(updateSql);

(2)

EntityCollection entityList = this.OrganizationService.RetrieveMultiple(expression);
if (entityList != null && entityList.Entities != null && entityList.Entities.Count > 0)
{
entity.Id = (Guid)entityList[0].Attributes["new_catalogueid"];
entity["new_code"] = dr["VALUE"].ToString();
entity["new_nameen"] = dr["VALUE_MEANING_EN"].ToString();
this.OrganizationService.Update(entity);
}

4.删除

Dynamic对实体进行增删改查

标签:org   rom   except   span   distinct   mic   opera   esc   tab   

原文地址:https://www.cnblogs.com/yaohongtao/p/12803581.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!