/// <summary>
        /// 把指定的ens 转换为 dataset
        /// </summary>
        /// <param name="spen">指定的ens</param>
        /// <returns>返回关系dataset</returns>
        public static DataSet ToDataSet(Entities spens)
        {
            DataSet ds = new DataSet(spens.ToString());

            /* 把主表加入DataSet */
            Entity    en = spens.GetNewEntity;
            DataTable dt = new DataTable();

            if (spens.Count == 0)
            {
                QueryObject qo = new QueryObject(spens);
                dt = qo.DoQueryToTable();
            }
            else
            {
                dt = spens.ToDataTableField();
            }
            dt.TableName   = en.EnDesc; //设定主表的名称。
            dt.RowChanged += new DataRowChangeEventHandler(dt_RowChanged);

            //dt.RowChanged+=new DataRowChangeEventHandler(dt_RowChanged);

            ds.Tables.Add(DealBoolTypeInDataTable(en, dt));


            foreach (EnDtl ed in en.EnMap.DtlsAll)
            {
                /* 循环主表的明细,编辑好关系并把他们放入 DataSet 里面。*/
                Entities  edens   = ed.Ens;
                Entity    eden    = edens.GetNewEntity;
                DataTable edtable = edens.RetrieveAllToTable();
                edtable.TableName = eden.EnDesc;
                ds.Tables.Add(DealBoolTypeInDataTable(eden, edtable));

                DataRelation r1 = new DataRelation(ed.Desc,
                                                   ds.Tables[dt.TableName].Columns[en.PK],
                                                   ds.Tables[edtable.TableName].Columns[ed.RefKey]);
                ds.Relations.Add(r1);


                //	int i = 0 ;

                foreach (EnDtl ed1 in eden.EnMap.DtlsAll)
                {
                    /* 主表的明细的明细。*/
                    Entities edlens1 = ed1.Ens;
                    Entity   edlen1  = edlens1.GetNewEntity;

                    DataTable edlensTable1 = edlens1.RetrieveAllToTable();
                    edlensTable1.TableName = edlen1.EnDesc;
                    //edlensTable1.TableName =ed1.Desc ;


                    ds.Tables.Add(DealBoolTypeInDataTable(edlen1, edlensTable1));

                    DataRelation r2 = new DataRelation(ed1.Desc,
                                                       ds.Tables[edtable.TableName].Columns[eden.PK],
                                                       ds.Tables[edlensTable1.TableName].Columns[ed1.RefKey]);
                    ds.Relations.Add(r2);
                }
            }


            return(ds);
        }