コード例 #1
0
        private Status Write <T>(T obj, Operation op, Predicate <T> where = null) where T : class, new()
        {
            SqlConnection connection = new SqlConnection(_conn);
            Status        status     = Status.Ok;

            try
            {
                ISqlRepositoryAdapter adapter = SqlCache.AdapterFor <T>();
                if (adapter == null)
                {
                    throw new InvalidOperationException(
                              string.Format("unable to use model '{0}' with sql store - not registered", typeof(T)));
                }

                connection.Open();
                status = adapter.Write(connection, obj, op);
            }
            catch (Exception err)
            {
                status = new Status(err);
            }
            finally
            {
                connection.Close();
            }

            return(status);
        }
コード例 #2
0
        public IEnumerable <T> Load <T>(Predicate <T> filter = null) where T : class, new()
        {
            SqlConnection   connection = new SqlConnection(_conn);
            IEnumerable <T> collection = Enumerable.Empty <T>();

            try
            {
                ISqlRepositoryAdapter adapter = SqlCache.AdapterFor <T>();
                if (adapter == null)
                {
                    throw new InvalidOperationException(
                              string.Format("unable to use model '{0}' with sql store - not registered", typeof(T)));
                }

                connection.Open();
                collection = (adapter as ISqlRepositoryAdapter <T>).Read(connection);
            }
            catch (Exception err)
            {
            }
            finally
            {
                connection.Close();
            }

            return(collection);
        }
コード例 #3
0
        internal static void RegisterAdapter <T>(ISqlRepositoryAdapter adapter)
        {
            if (_adapters.ContainsKey(typeof(T)))
            {
                throw new InvalidOperationException(
                          string.Format("adapter for '{0}' is already registered", typeof(T)));
            }

            _adapters.Add(typeof(T), adapter);
        }