公司代码速查

ParameterBase.CurrentUser.UserId
ICustomerDeskDetailManager customerDeskDetailManager = ClientProxyFactory.CreateProxyInstance<ICustomerDeskDetailManager>();

使用主键查询一个实体

CustomerEntity _Customer = new CustomerEntity(CustomerNo);
DataAccessAdapterBase adapter = GetCompanyDataAccessAdapter();
{
bool found = adapter.FetchEntity(_Customer, prefetchPath, null, fieldList);
if (!found) throw new Foundation.Common.RecordNotFoundException(CustomerNo, "Invalid customer");
}
return _Customer;

根据条件查找实体集

EntityCollection CustomerCollection = new EntityCollection(new CustomerEntityFactory());
using (DataAccessAdapterBase adapter = GetCompanyDataAccessAdapter())
{
adapter.FetchEntityCollection(CustomerCollection, filterBucket, , sortExpression, prefetchPath, fieldList);
}
return CustomerCollection;

实体集内存过滤

EntityView2<SalesOrderDetailEntity> orderDetail = new EntityView2<SalesOrderDetailEntity>(salesOrder.SalesOrderDetails);
ISortExpression sorter = new SortExpression(SalesOrderDetailFields.EntryNo | SortOperator.Ascending);
orderDetail.Sorter = sorter;

保存实体

using (DataAccessAdapterBase adapter = GetCompanyDataAccessAdapter())
{
try
{
adapter.StartTransaction(IsolationLevel.ReadCommitted, "SaveCustomerGroup");
adapter.SaveEntity(CustomerGroup, true, false);
adapter.Commit();
}
catch
{
adapter.Rollback();
throw;
}
}
return CustomerGroup;

删除实体

using (DataAccessAdapterBase adapter = GetCompanyDataAccessAdapter())
{
try
{
adapter.StartTransaction(IsolationLevel.ReadCommitted, "DeleteCustomerGroup");
adapter.DeleteEntity(CustomerGroup);
adapter.Commit();
}
catch
{
adapter.Rollback();
throw;
}
}

Count(*)写法

using (DataAccessAdapterBase adapter = GetCompanyDataAccessAdapter())
{
if (filterBucket == null)
filterBucket = new RelationPredicateBucket();
return (int)adapter.GetScalar(CustomerGroupFields.CustomerGroup, null, AggregateFunction.Count, filterBucket.PredicateExpression);
}

过滤条件写法

IRelationPredicateBucket bucket = new RelationPredicateBucket();
bucket.PredicateExpression.Add(CustomerDeskDetailFields.DeskName == list[].SysDeskName);

判断是否为空

bucket.PredicateExpression.Add(JobOrderMaterialPickDetailFields.SourceEntryNo == DBNull.Value);

关联过滤

//系统有外键,直接调用
bucket.Relations.Add(InventoryMovementEntity.Relations.InventoryMovementDetailEntityUsingRefNo);
//系统无外键,通过这种方式创建;JoinHint与写的顺序相反
bucket.Relations.Add(new EntityRelation(ItemFields.ItemNo, InventoryMovementDetailFields.ItemNo, RelationType.OneToMany), JoinHint.Left);

使用别名关联

//主实体必须放在后面
bucket.Relations.Add(new EntityRelation(LocationFields.Loc,JobOrderMaterialPickFields.LocFrom, RelationType.OneToMany),"LocFrom", JoinHint.Left);

多键关联

IEntityRelation mulKeyRelation = new EntityRelation(JobOrderMaterialPickDetailFields.SourceRefNo, PurchaseOrderDetailFields.OrderNo, RelationType.ManyToOne);
mulKeyRelation.AddEntityFieldPair(JobOrderMaterialPickDetailFields.SourceEntryNo, PurchaseOrderDetailFields.EntryNo);
bucket.Relations.Add(mulKeyRelation, JoinHint.Right);//系统无外键,通过这种方式创建

在结果集中搜索

List<int> ids = customerDeskCollection.FindMatches(CustomerDeskDetailFields.TableName == item.TableName);

搜索出新的结果集

IPredicate filterBucket1 = (GcBomAmendmentFields.Change == true);
sortExpression = new SortExpression();
sortExpression.Add(GcBomAmendmentFields.EntryNo | SortOperator.Ascending);
EntityView2<GcBomAmendmentEntity> entityView1 = new EntityView2<GcBomAmendmentEntity>(collection);
entityView1.Filter = filterBucket1;
entityView1.Sorter = sortExpression;
EntityCollection<GcBomAmendmentEntity> changeCollection = (EntityCollection<GcBomAmendmentEntity>)entityView1.ToEntityCollection();

关联读取实体

IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.PurchaseOrderEntity);
IPrefetchPathElement2 element = prefetchPath.Add(PurchaseOrderEntity.PrefetchPathPurchaseOrderDetails);
element.SubPath.Add(PurchaseOrderDetailEntity.PrefetchPathPurchaseOrderBomDetails);

排序条件

ISortExpression sortExpression = new SortExpression();
sortExpression.Add(CustomerDeskFields.SortNo | SortOperator.Ascending);

复杂的公式(ISNULL(QtyReceipt,0)>ISNULL(QtyCosting,0))

DbFunctionCall dbFunQtyReceipt = new DbFunctionCall("ISNULL", new object[] { (PurchaseReceiptsDetailFields.QtyReceipt),  });
DbFunctionCall dbFunQtyCosting = new DbFunctionCall("ISNULL", new object[] { (PurchaseReceiptsDetailFields.QtyCosting), });
EntityField2 eQtyReceipt = new EntityField2("QtyReceipt", dbFunQtyReceipt);
EntityField2 eQtyCosting = new EntityField2("QtyCosting", dbFunQtyCosting);
bucketInspection.PredicateExpression.Add(new FieldCompareExpressionPredicate(eQtyReceipt, null, ComparisonOperator.GreaterThan, new Expression(eQtyCosting)));

复杂的公式(SUM(ISNULL(eQtyOnHand,0)-ISNULL(QtyReserved,0)))

DbFunctionCall dbFunQtyOnHand = new DbFunctionCall("ISNULL", new object[] { (InventoryBalanceFields.QtyOnHand),  });
DbFunctionCall dbFunQtyReserved = new DbFunctionCall("ISNULL", new object[] { (InventoryBalanceFields.QtyReserved), });
EntityField2 eQtyOnHand = new EntityField2("QtyOnHand", dbFunQtyOnHand);
EntityField2 eQtyReserved = new EntityField2("QtyReserved", dbFunQtyReserved);
IExpression expression = new Expression(eQtyOnHand, ExOp.Sub, eQtyReserved);
object qtyBalance = adapter.GetScalar(InventoryBalanceFields.QtyOnHand.SetExpression(expression), null, AggregateFunction.Sum, filterBucket.PredicateExpression);
qtyBalance == DBNull.Value ? 0 : (decimal)qtyBalance;

保存时不验证

entity.Validator = null;
adapter.SaveEntity(entity, true, false);

选择读取的列

ExcludeIncludeFieldsList fields = new ExcludeIncludeFieldsList(false);
fields.Add(FiscalPeriodFields.EndDate);

自定义读取表数据

ResultsetFields fields = new ResultsetFields();
fields.DefineField(InventoryMovementFields.RefNo, );
fields.DefineField(InventoryMovementFields.LocFrom, );
fields.DefineField(ProductionInspectionFields.JobNo, , "InspectionJobNo");//关联表的数据,以及创建别名
//获取
IUserDefinedQueryManager userDefinedQueryManager = ClientProxyFactory.CreateProxyInstance<IUserDefinedQueryManager>();
_productionIssueTable = userDefinedQueryManager.GetQueryResult(fields, bucket, sortExpression, null, true, , false);

直接删除 Delete From A Where

IRelationPredicateBucket bucket = new RelationPredicateBucket((CustomerFields.CustomerID == "FISSA"));
DataAccessAdapter adapter = new DataAccessAdapter();
adapter.DeleteEntitiesDirectly("CustomerEntity", bucket);

直接更新 Update A set Where

var ShipmentImportTmpChangedEntity = new ShipmentImportTmpEntity();

ShipmentImportTmpChangedEntity.TransactionType = "FeedBack";//直接赋值
ShipmentImportTmpChangedEntity.Fields[(int)ShipmentImportTmpFieldIndex.TransactionType].ExpressionToApply =
new Expression(ShipmentImportTmpFields.PaymentType);//等于另外一个字段
ShipmentImportTmpChangedEntity.Fields[(int)ShipmentImportTmpFieldIndex.TransactionType].ExpressionToApply =
(ShipmentImportTmpFields.PaymentType + ShipmentImportTmpFields.TransactionType);//等于表达式 IRelationPredicateBucket bucket2 = new RelationPredicateBucket();
bucket2.PredicateExpression.Add(ShipmentImportTmpFields.PaymentType == "Amazon fees");
adapter.UpdateEntitiesDirectly(ShipmentImportTmpChangedEntity, bucket2); //实际应该把其他的值设置为false,防止同时更新,然后使用currentValue赋值,防止发生连带赋值
InventoryMovementDetailEntity updateMovDetails = new InventoryMovementDetailEntity();
foreach (IEntityField2 field in updateMovDetails.Fields) { field.IsChanged = false; }
updateMovDetails.Fields[(int)InventoryMovementDetailFieldIndex.CreatedDate].CurrentValue = DateTime.Now;
adapter.UpdateEntitiesDirectly(updateMovDetails, bucket);

事务

using (DataAccessAdapterBase adapter = GetCompanyDataAccessAdapter())
{
try{
adapter.StartTransaction(IsolationLevel.ReadCommitted, "SalesShipmentImportOrder");
使用LLBL基本的语句写
adapter.Commit();
}
catch
{
adapter.Rollback();
throw;
}

 select * from A where A.xx in (select yy from B)

bucket.PredicateExpression.Add(new FieldCompareSetPredicate(
JobOrderMaterialPickDetailFields.SourceRefNo, null, JobOrderFields.JobNo, null,
SetOperator.In, bucket.PredicateExpression, bucket.Relations));

【C#技术】一篇文章搞掂:LLBL的更多相关文章

  1. 【进阶技术】一篇文章搞掂:Spring Cloud Stream

    本文总结自官方文档http://cloud.spring.io/spring-cloud-static/spring-cloud-stream/2.1.0.RC3/single/spring-clou ...

  2. 【已转移】【Java架构:基础技术】一篇文章搞掂:Spring

    本文篇幅较长,建议合理利用右上角目录进行查看(如果没有目录请刷新). 本文是对<SPRING实战第4版>的总结,大家也可以去仔细研读该书 [------------------------ ...

  3. 【Java架构:进阶技术】——一篇文章搞掂:JVM调优

    Sun官方定义的Java技术体系: Java程序设计语言 各种硬件平台上的Java虚拟机 Class文件格式 Java API类库 来自商业机构和开源社区的第三方Java类库 JDK(Java Dev ...

  4. 【进阶技术】一篇文章搞掂:OAuth2

    一.第一步 1.什么是OAuth2,为什么应该了解 应用程序请求资源所有者进行认证,并接受tokens来访问这些资源应用程序不是以控制资源的“人”的角度去访问资源,而是用许可证举例,备用钥匙,车主主钥 ...

  5. 【进阶技术】一篇文章搞掂:Spring高级编程

    本文篇幅较长,建议合理利用右上角目录进行查看(如果没有目录请刷新). 本文基于<Spring5高级编程>一书进行总结和扩展,大家也可以自行研读此书. 十一.任务调度 任务调度主要由三部分组 ...

  6. 【Java架构:基础技术】一篇文章搞掂:Spring Boot 官方文档解读

    本文篇幅较长,建议合理利用右上角目录进行查看(如果没有目录请刷新). 本文内容大部分是翻译和总结官方文档,可以到https://docs.spring.io/spring-boot/docs查看(此地 ...

  7. 【Java架构:基础技术】一篇文章搞掂:Spring Boot

    本文篇幅较长,建议合理利用右上角目录进行查看(如果没有目录请刷新). 本文是对<Spring Boot 实战第4版>的总结,大家也可以去仔细研读该书 注意,书中使用的Spring Boot ...

  8. 【已转移】【Java架构:基础技术】一篇文章搞掂:Java 8

    本文篇幅较长,建议合理利用右上角目录进行查看(如果没有目录请刷新). 一.Java的历史与演变 目的:为完全了解Java,需要理解Java的诞生原因.成型动力以及他继承的思想. 计算机语言的创新与发展 ...

  9. 【前端技术】一篇文章搞掂:uni-app

    语法 //列表遍历,遍历数组,第一个参数为数组中元素,可以给第二个参数作为索引值 <view v-for="(item, itemIndex) in card" :key=& ...

随机推荐

  1. getcwd函数学习

    getcwd 函数原型:char *getcwd( char *buffer, int maxlen ); 功 能:获取当前工作目录 参数说明:getcwd()会将当前工作目录的绝对路径复制到参数bu ...

  2. Security基础(二):SELinux安全防护、加密与解密应用、扫描与抓包分析

    一.SELinux安全防护 目标: 本案例要求熟悉SELinux防护机制的开关及策略配置,完成以下任务: 将Linux服务器的SELinux设为enforcing强制模式 在SELinux启用状态下, ...

  3. delphi 动态获取文件类型的图标

    delphi 动态获取文件类型的图标.txt我不奢望什么,只希望你以后的女人一个不如一个.真怀念小时候啊,天热的时候我也可以像男人一样光膀子!在应用程序的编写中,组合框(ComboBox).列表框(L ...

  4. mysql5.6配置详解

    系统 4核 16G Centos6.5 x64 优化后测试结果如下 #mysqlslap #--concurrency=2 #--iterations=1 #--number-int-cols=10 ...

  5. 安装纯净版debian!

    kali更新了1.1.0a,不知道新版的内核哪地方有bug,用着用着就卡死了,一怒之下卸载了装debian. 下载的netinst只有200M,基本上就是刚好能用,不要用硬盘装,会找不到网卡,无线也没 ...

  6. VMware里克隆出来的CentOS Linux device eth0 does not seem to be present, delaying initialization

    解决办法:1.ifconfig eth1 确定新网卡的MAC地址.nmcli con 确定新网卡的UUIDvim /etc/udev/rules.d/70-persistent-net.rules把原 ...

  7. Struts1.3——Struts入门

    1.Struts的几个基本概念 1.struts是一个开源框架(frameset) 2.struts是一个Web框架 3.struts是一个基于MVC的Web框架 2.为什么有struts 因为我们对 ...

  8. JeeSite配置多数据源方案

    jeesite简介 JeeSite是基于多个优秀的开源项目,高度整合封装而成的高效,高性能,强安全性的 开源 Java EE快速开发平台. JeeSite本身是以Spring Framework为核心 ...

  9. Java中的session详解

    一.Session简单介绍 在WEB开发中,服务器可以为每个用户浏览器创建一个会话对象(session对象),注意:一个浏览器独占一个session对象(默认情况下).因此,在需要保存用户数据时,服务 ...

  10. 为 STM32 移植 Berry 脚本语言

    Berry 是我为单片机设计的一款脚本语言,该语言具有资源占用小.平台无关.执行速度快和易于掌握等优点.在单片机上使用脚本语言可以提高单片机的二次开发能力以及调试效率,同时也是一种比较新颖的玩法.本教 ...