예제 #1
0
        public IEnumerable <Event> SelectEvents(int from, int max)
        {
            if (orderColumns != null && orderDirections != null &&
                orderColumns.Length != orderDirections.Length)
            {
                throw new ArgumentException();
            }

            using (SqlConnection cn = new SqlConnection(connectionString))
            {
                cn.Open();
                using (SqlTransaction tn = cn.BeginTransaction(IsolationLevel.ReadUncommitted))
                {
                    using (SqlCommand cmd = new SqlCommand(string.Empty, cn, tn))
                    {
                        CreateSelectQuery(cmd, from, max);
                        cmd.CommandType = CommandType.Text;

                        using (SqlDataReader dr = cmd.ExecuteReader())
                        {
                            while (dr.Read())
                            {
                                Event e = new Event();
                                e.LoadFromDataReader(dr);
                                yield return(e);
                            }
                        }
                    }

                    tn.Commit();
                }
            }
        }
예제 #2
0
        public Event LoadEvent(long eventId)
        {
            var e = new Event();

            using (SqlConnection cn = new SqlConnection(connectionString))
            {
                cn.Open();
                using (SqlTransaction tn = cn.BeginTransaction(IsolationLevel.ReadUncommitted))
                {
                    using (SqlCommand cmd = new SqlCommand("spGetEvent", cn, tn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;

                        cmd.Parameters.Add("@EventID", SqlDbType.BigInt).Value = eventId;

                        using (SqlDataReader dr = cmd.ExecuteReader())
                        {
                            while (dr.Read())
                            {
                                e.LoadFromDataReader(dr);
                            }
                        }
                    }

                    using (SqlCommand cmd = new SqlCommand("spGetEventData", cn, tn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;

                        cmd.Parameters.Add("@EventID", SqlDbType.BigInt).Value = eventId;

                        using (SqlDataReader dr = cmd.ExecuteReader())
                        {
                            while (dr.Read())
                            {
                                int o    = 1;
                                var key  = dr.GetString(o++);
                                var data = dr.GetValue(o++);

                                e.UserData.Add(key, data);
                            }
                        }
                    }


                    tn.Commit();
                }
            }

            return(e);
        }