公司代码速查

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. POJ 3126 Prime Path (bfs+欧拉线性素数筛)

    Description The ministers of the cabinet were quite upset by the message from the Chief of Security ...

  2. React的contextType的使用方法简介

    上一篇介绍了Context的使用方法.但是Context会让组件变得不纯粹,因为依赖了全局变量.所以这决定了Context一般不会大规模的使用.所以一般在一个组件中使用一个Context就好. 由于C ...

  3. 运放参数的详细解释和分析-part1,输入偏置电流和输入失调电流【转】

    一般运放的datasheet中会列出众多的运放参数,有些易于理解,我们常关注,有些可能会被忽略了.在接下来的一些主题里,将对每一个参数进行详细的说明和分析.力求在原理和对应用的影响上把运放参数阐述清楚 ...

  4. CCflow与基础框架组织机构整合

    SELECT No,Name,Pass,FK_Dept,SID FROM Port_Emp SELECT No,Name,ParentNo FROM Port_Dept SELECT No,Name, ...

  5. ubuntu 开机启动shell脚本

    1.创建shell启动脚本test 2.将启动脚本复制到 /etc/init.d 目录下 3.设置脚本文件权限 sudo chmod 755 /etc/init.d/test 4.设置脚本启动 sud ...

  6. cannot find module node-sass

    解决方法: npm install --save-dev node-sass

  7. Centos7使用Python3

    1.安装python3替换python2.7 [root@Python src]# wget https://www.python.org/ftp/python/3.5.4/Python-3.5.4. ...

  8. 开发效率优化之Git分布式版本控制系统(一)

    阿里P7移动互联网架构师进阶视频(每日更新中)免费学习请点击:https://space.bilibili.com/474380680本篇文章将先从Git分布式版本控制系统来阐述开发效率优化 一,企业 ...

  9. FrameWork内核解析之WindowManagerService(一)中篇

    阿里P7Android高级架构进阶视频免费学习请点击:https://space.bilibili.com/474380680 1.WMS概述 WMS是系统的其他服务,无论对于应用开发还是Framew ...

  10. texinfo - 软件文档系统

    DESCRIPTION 描述 Texinfo 是一种文档系统,使用单一的源文件来产生在线文档以及可打印的输出.它主要用于书写软件使用手册. 要查看 Texinfo 语言和相关工具的全面描述,请查看 T ...