一:动态拼接条件查询
var expression = PredicateBuilder.True<OQC_MES_INF_UL_QMS_OFFLINE>(); SYS_ROLES_CONFIG rule = context.SysRolesConfig.Single(t => t.ORG_ID == orgid&&t.STATE=="A"); StringBuilder sb = new StringBuilder(); sb.Append("该机身条码在与当前抽检"); if (!string.IsNullOrEmpty(rule.SYS_PARMS1)) { //同生产工单 expression = expression.And(a => a.MO_NAME == model.WORK_ORDER_ID); sb.Append("同生产工单、"); } int count = context.OQC_MES_INF_UL_QMS_OFFLINE.Get(expression).Count();
二:左连接
var result1 = from a in context.OQC_ASS_PARTS_V_INF join b in context.INV_MITEM on a.PRIMARY_ITEM_ID equals b.CODE where a.STATE == StateConverter.Active && a.ORG_ID == ORG_ID && a.ORG_ID == b.ORG_ID && a.WIP_ENTITY_NO == WORK_ORDER_ID select new { WIP_ENTITY_ID = a.WIP_ENTITY_ID, PROID = a.PRIMARY_ITEM_NAME, WIP_ENTITY_NO = a.WIP_ENTITY_NO, START_QUANTITY = a.START_QUANTITY, EATTRIBUTE1 = b.EATTRIBUTE1, COMPLETE_DATE = a.SCHEDULED_COMPLETION_DATE, SCHEDULE_GROUP = a.SCHEDULE_GROUP_NAME, PRODUCTION_LINE = a.EATTRIBUTE1 }; var result2 = from a in context.OQC_ASS_PARTS_V_INF join c in context.OQC_OMS_IF_QMS_ORDERINFO_V_INF on a.PRIMARY_ITEM_NAME equals c.MRP_ITEM_CODE where a.STATE == StateConverter.Active && a.ORG_ID == ORG_ID && a.ORG_ID == c.ORG_ID && a.WIP_ENTITY_NO == WORK_ORDER_ID select new { WIP_ENTITY_ID = a.WIP_ENTITY_ID, CONSUME_COUNTRY = c.CONSUME_COUNTRY, CUSTOMER_NAME = c.CUSTOMER_NAME, CUSTOMER_CODE = c.CUSTOMER_CODE }; var result3 = from aa in result1 join bb in result2 on aa.WIP_ENTITY_ID equals bb.WIP_ENTITY_ID into cc from bb in cc.DefaultIfEmpty() select new { //产品编码 PROID = aa.PROID, //生产工单 WIP_ENTITY_NO = aa.WIP_ENTITY_NO, //工单数量 START_QUANTITY = aa.START_QUANTITY, //产品型号 EATTRIBUTE1 = aa.EATTRIBUTE1, //完工时间 COMPLETE_DATE = aa.COMPLETE_DATE, //车间 SCHEDULE_GROUP = aa.SCHEDULE_GROUP, //客户订单号 CUSTOMER_CODE = bb.CUSTOMER_CODE, //客户名称 CUSTOMER_NAME = bb.CUSTOMER_NAME, //销往地 CONSUME_COUNTRY = bb.CONSUME_COUNTRY, //作业产线信息 PRODUCTION_LINE=aa.PRODUCTION_LINE }; var rs = result3.FirstOrDefault();