public static PrjType GetByItemCode(string typeCode, int itemCode) { PrjType type = new PrjType(); using (pm2Entities entities = new pm2Entities()) { return((from m in entities.Basic_CodeList where (m.TypeCode == typeCode) && (m.ItemCode == itemCode) select new PrjType { TypeCode = m.TypeCode, ItemCode = m.ItemCode, ItemName = m.ItemName }).FirstOrDefault <PrjType>()); } }
public static void Update(PrjType prjType) { using (pm2Entities entities = new pm2Entities()) { Basic_CodeList list = (from m in entities.Basic_CodeList where (m.ItemCode == prjType.ItemCode) && (m.TypeCode == prjType.TypeCode) select m).FirstOrDefault <Basic_CodeList>(); if (list == null) { throw new Exception("没有找到要修改的工程类型"); } list.ItemName = prjType.ItemName; entities.SaveChanges(); } }
public static void Add(PrjType prjType) { using (pm2Entities entities = new pm2Entities()) { Basic_CodeList list = new Basic_CodeList { TypeCode = prjType.TypeCode, ItemCode = prjType.ItemCode, ItemName = prjType.ItemName }; Basic_CodeType type = (from c in entities.Basic_CodeType where c.TypeCode == prjType.TypeCode select c).FirstOrDefault <Basic_CodeType>(); if (type != null) { list.Basic_CodeType = type; } entities.AddToBasic_CodeList(list); entities.SaveChanges(); } }