遗忘海岸

江湖程序员 -Feiph(LM战士)

导航

EF参数化查询

 string cmdText = @"select FGPartNO PartNO,p_FGName PartName,
                   partno MNo,p_partnoName MName,
                   partnoqty Qty, UM [Unit]
            from singleBom Where Used='Y' And FGPartNo={0}";

            string key=partNo.Trim().ToLower();
            List<BOMInfo> bom = null;

            if(!BOMDic.ContainsKey(key))
            {
                using (var ctx = DBFactory.NewCtx())
                {
                    var list= ctx.ExecuteStoreQuery<BOMInfo>(cmdText, partNo).ToList();
                    if (list.Count == 0) throw new Exception("未创建物料{0}的BOM记录!");
                    BOMDic[key] = list;
                }
            }
            bom = BOMDic[key];
            return bom;

类似String.Format 使用{x},注意不管什么类型都不要要加''

posted on 2012-12-24 08:34  遗忘海岸  阅读(760)  评论(0编辑  收藏  举报