internal static EntityData[] GetEntities(string connStr)
        {
            SqlConnection conn = new SqlConnection(connStr);
            SqlCommand cmd = new SqlCommand("select TABLE_CATALOG, TABLE_NAME from INFORMATION_SCHEMA.TABLES; select TABLE_CATALOG, TABLE_NAME, COLUMN_NAME, DATA_TYPE from INFORMATION_SCHEMA.COLUMNS", conn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);

            Dictionary<string, EntityData> entities = new Dictionary<string, EntityData>();

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                string className = dr["TABLE_NAME"].ToString();
                className = className.Replace("Book_", "");
                entities.Add(className, new EntityData(className));
            }

            foreach (DataRow dr in ds.Tables[1].Rows)
            {
                EntityType t = new EntityType();
                t.Name = dr["COLUMN_NAME"].ToString();
                t.SetSqlDbType(dr["DATA_TYPE"].ToString());
                t.SetType(dr["DATA_TYPE"].ToString());
                t.IsKey = (t.Name.ToUpper() == "ID") ? true : false;
                entities[dr["TABLE_NAME"].ToString().Replace("Book_", "")].F.Add(t);
            }

            EntityData[] result = new EntityData[entities.Count];
            entities.Values.CopyTo(result, 0);

            return result;
        }
        public static string CreateEntityClass(EntityData entity, string template)
        {
            StringBuilder resultCode = new StringBuilder("///©pavel timofeev");
            Regex r = new Regex("<%CN%>");
            resultCode.Append(r.Replace(template, entity.CN));

            resultCode = resultCode.Replace("<%FF%>", entity.F.GetFF());
            resultCode = resultCode.Replace("<%Ff%>", entity.F.GetFf());
            resultCode = resultCode.Replace("<%FP%>", entity.F.GetFP());
            resultCode = resultCode.Replace("<%FS%>", entity.F.GetFS());

            StringReader s = new StringReader(resultCode.ToString());
            StringWriter w = new StringWriter();
            string stroke = s.ReadLine();
            while (stroke != null)
            {
                if (!stroke.StartsWith("//"))
                    w.WriteLine(ReplaceTypes(stroke, entity));
                stroke = s.ReadLine();
            }

            string str = w.ToString();

            return str;
        }
        private static string ReplaceTypes(string stroke, EntityData entity)
        {
            if (stroke == null)
                return null;

            string result = stroke.TrimStart(' ');
            if (result.StartsWith(">>"))
            {
                result = result.Remove(0, 2);

                string temp = "";

                for (int i = 0; i < entity.F.Count; i++)
                {
                    if (!entity.F[i].IsKey)
                        temp += entity.F[i].Format(result) + "\r\n";
                }
                result = temp;

            }
            return result;
        }