Пример #1
0
        public Dictionary <EnumType, DaoType> FillEnumDictionary <EnumType, DaoType>(Dictionary <EnumType, DaoType> dictionary, string nameColumn) where DaoType : Dao, new()
        {
            QuerySet query = ExecuteQuery <DaoType>();

            QueryResult result = ((QueryResult)query.Results[0]);

            if (result.DataTable.Rows.Count == 0)
            {
                InitEnumValues <EnumType, DaoType>("Value", nameColumn);
                query  = ExecuteQuery <DaoType>();
                result = ((QueryResult)query.Results[0]);
            }

            foreach (DataRow row in result.DataTable.Rows)
            {
                EnumType enumVal = (EnumType)Enum.Parse(typeof(EnumType), (string)row[nameColumn]);
                DaoType  inst    = new DaoType();
                inst.DataRow = row;
                dictionary.AddMissing(enumVal, inst);
            }

            return(dictionary);
        }
Пример #2
0
        private X EnsureXref(L item, Database db = null)
        {
            db = db ?? Database;
            if (item.IdValue != null && XrefsByListId.ContainsKey(item.IdValue.Value))
            {
                return(XrefsByListId[item.IdValue.Value]);
            }
            else
            {
                if (item.IsNew)
                {
                    item.Save(db);
                }

                X        result = null;
                QuerySet q      = Dao.GetQuerySet(db);
                q.Select <X>().Where(new QueryFilter(ListColumnName) == item.IdValue.Value && new QueryFilter(ParentColumnName) == Parent.IdValue);

                q.Execute(db);
                if (q.Results[0].DataTable.Rows.Count > 0)
                {
                    result         = new X();
                    result.DataRow = q.Results[0].DataTable.Rows[0];
                }
                else
                {
                    result = new X();
                    result.SetValue(string.Format("{0}Id", Parent.GetType().Name), Parent.IdValue);
                    result.SetValue(string.Format("{0}Id", typeof(L).Name), item.IdValue);
                    result.Save(db);

                    XrefsByListId.Add(item.IdValue.Value, result);
                }

                return(result);
            }
        }