/// <summary>
 /// 创建一个数据字典
 /// </summary>
 /// <param name="db">实体数据</param>
 /// <param name="entity">将要创建的一个数据字典</param>
 public void Create(SysEntities db, SysField entity)
 {
     if (entity != null)
     {
         db.SysField.AddObject(entity);
     }
 }
 /// <summary>
 /// 创建一个数据字典
 /// </summary>
 /// <param name="entity">一个对象</param>
 /// <returns></returns>
 public int Create(SysField entity)
 {
     using (SysEntities db = new SysEntities())
     {
         Create(db, entity);
         return(this.Save(db));
     }
 }
        /// <summary>
        /// 删除一个数据字典
        /// </summary>
        /// <param name="db">实体数据</param>
        /// <param name="id">一条数据字典的主键</param>
        public void Delete(SysEntities db, string id)
        {
            SysField deleteItem = GetById(db, id);

            if (deleteItem != null)
            {
                db.SysField.DeleteObject(deleteItem);
            }
        }
        /// <summary>
        /// 判断是否存在引用
        /// </summary>
        /// <param name="db">数据库上下文</param>
        /// <param name="field">字典表对象</param>
        /// <returns>是否存在引用(true:是,false:否)</returns>
        public bool ExistsReference(SysEntities db, SysField field)
        {
            bool bResult = false;

            if (db != null && field != null)
            {
                String sql    = String.Format("select Value o from SysEntities.{0} as o where o.{1}=@id", field.MyTables, field.MyColums);
                var    reader = db.CreateQuery <DbDataReader>(sql, new ObjectParameter("id", field.Id));
                bResult = reader.Count() > 0;
            }

            return(bResult);
        }
 /// <summary>
 /// 编辑一个数据字典对象
 /// </summary>
 /// <param name="db">实体数据</param>
 /// <param name="entity">将要编辑的一个数据字典对象</param>
 public SysField Edit(SysEntities db, SysField entity)
 {
     db.SysField.Attach(entity);
     db.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);
     return(entity);
 }