コード例 #1
0
        public IQueryable <T> Select(Expression <Func <T, bool> > expression)
        {
            List <T>      list = new List <T>();
            StringBuilder sb   = new StringBuilder();

            sb.Append("(Select * From ").Append(Entity.TableName).Append(" Where ");

            sb.Append(new WhereTranslator().Translate(expression));

            sb.Append(")");
            IDbCommand cmd = connection.CreateCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = sb.ToString();
            IDataReader dr = null;

            try
            {
                dr = cmd.ExecuteReader() as MySqlDataReader;
                var map = new MappingColumn(Entity);
                list = map.MappingWithoutInclud <T>(dr);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                dr.Close();
            }
            return(list.AsQueryable());
        }
コード例 #2
0
        public IQueryable <T> Select(Expression <Func <T, dynamic> > expression)
        {
            EntityInfo    entity = new EntityInfo(typeof(T));
            List <T>      list   = new List <T>();
            StringBuilder sb     = new StringBuilder();
            var           job    = new CollectPropertyFromExpression().Translate(expression);

            sb.Append("Select ");
            if (job.Count < 1)
            {
                sb.Append(" * ");
            }
            else
            {
                int count = job.Count;
                for (int i = 0; i < count; i++)
                {
                    var att = entity.GetAttributDbColumn(job[i]);

                    sb.Append(string.Format("{0}", att));
                    if (i < count)
                    {
                        sb.Append(", ");
                    }
                }
            }
            string temp = sb.ToString();

            sb.Clear();

            temp = temp.Substring(0, temp.Length - 2);
            sb.Append(temp + " ");
            sb.Append(" From ").Append(Entity.TableName);

            //    sb.Append(new WhereTranslator().Translate(expression));
            IDbCommand cmd = connection.CreateCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = sb.ToString();
            IDataReader dr = null;

            try
            {
                dr = cmd.ExecuteReader() as MySqlDataReader;
                var map = new MappingColumn(Entity);
                list = map.MappingWithoutInclud <T>(dr);
            }
            catch (MySqlException ex)
            {
                throw new  SystemException(ex.Message);
            }
            finally
            {
                if (dr != null)
                {
                    dr.Close();
                }
            }
            return(list.AsQueryable());
        }
コード例 #3
0
        public IQueryable <T> SelectAll()
        {
            List <T>      list = new List <T>();
            StringBuilder sb   = new StringBuilder();

            sb.Append("Select * From ").Append(Entity.TableName);
            IDataReader dr = null;

            try
            {
                IDbCommand cmd = connection.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = sb.ToString();
                dr = cmd.ExecuteReader();
                var mapping = new MappingColumn(Entity);
                mapping.ReaderSchema = this.ReadColumnInfo(dr.GetSchemaTable());
                list = mapping.MappingWithoutInclud <T>(dr);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                dr.Close();
            }
            return(list.AsQueryable <T>());
        }
コード例 #4
0
        public IQueryable <T> Includ(IQueryable <T> query, Expression <Func <T, dynamic> > expression)
        {
            var job = new CollectPropertyFromExpression().Translate(expression);

            foreach (T Item in query)
            {
                foreach (PropertyInfo propertyJOb in job)
                {
                    EntityInfo entityChild = null;
                    if (propertyJOb.PropertyType.GenericTypeArguments.Count() > 0)
                    {
                        entityChild = new EntityInfo(propertyJOb.PropertyType.GenericTypeArguments[0]);
                        string vsql = new InsertQuery(Entity).GetChildInsertQuery(propertyJOb, Item, entityChild);
                        if (vsql != string.Empty)
                        {
                            IDataReader dr = null;
                            try
                            {
                                IDbCommand cmd = connection.CreateCommand();
                                cmd.CommandType = CommandType.Text;
                                cmd.CommandText = vsql;
                                dr = cmd.ExecuteReader();

                                var   propertyproduct = Entity.GetPropertyByPropertyName(propertyJOb.Name);
                                IList list            = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(entityChild.GetEntityType()));
                                var   map             = new MappingColumn(Entity);
                                var   resultMapping   = (IList)map.MappingWithoutInclud(dr, entityChild.GetEntityType());

                                foreach (var item in resultMapping)
                                {
                                    list.Add(item);
                                }

                                propertyproduct.SetValue(Item, list, null);
                            }
                            catch (Exception ex)
                            {
                                throw new System.Exception(ex.Message);
                            }
                            finally
                            {
                                if (dr != null)
                                {
                                    dr.Close();
                                }
                            }
                        }
                    }
                    else
                    {
                        entityChild = new EntityInfo(propertyJOb.ReflectedType);
                    }
                }
            }
            return(query);
        }
コード例 #5
0
        public TracingModel GetPenjualan(int STT)
        {
            using (var db = new OcphDbContext())
            {
                try
                {
                    var cmd = db.CreateCommand();
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.CommandText = "GetPenjualan";
                    cmd.Parameters.Add(new MySql.Data.MySqlClient.MySqlParameter("STT", STT));
                    var reader = cmd.ExecuteReader();
                    var mapp   = new MappingColumn(new EntityInfo(typeof(TracingModel)));
                    var result = mapp.MappingWithoutInclud <TracingModel>(reader);

                    reader.Close();

                    var tracing = result.FirstOrDefault();
                    if (result != null)
                    {
                        var packlists = db.PackingLists.Where(O => O.PenjualanId == tracing.Id).GroupBy(O => O.ManifestID).ToList();
                        tracing.Manifests = new List <manifestoutgoing>();
                        foreach (var item in packlists)
                        {
                            var manifest = db.Outgoing.Where(O => O.Id == item.Key).FirstOrDefault();
                            if (manifest != null)
                            {
                                tracing.Manifests.Add(manifest);
                            }
                        }
                        return(tracing);
                    }
                    else
                    {
                        throw new SystemException(MessageCollection.Message(MessageType.NotFound));
                    }
                }
                catch (Exception ex)
                {
                    throw new SystemException(ex.Message);
                }
            }
        }
コード例 #6
0
        public IQueryable <T> Select(Expression <Func <T, bool> > expression)
        {
            List <T>      list = new List <T>();
            StringBuilder sb   = new StringBuilder();

            sb.Append("Select * From ").Append(Entity.TableName).Append(" Where ");

            sb.Append(new WhereTranslator().Translate(expression));

            IDbCommand cmd = connection.CreateCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = sb.ToString();
            IDataReader dr = null;

            try
            {
                dr = cmd.ExecuteReader();
                if (dr != null)
                {
                    var mapping = new MappingColumn(Entity);
                    mapping.ReaderSchema = this.ReadColumnInfo(dr.GetSchemaTable());
                    list = mapping.MappingWithoutInclud <T>(dr);
                }
                else
                {
                    throw new SystemException("Data Tidak Ditemukan");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                dr.Close();
            }
            return(list.AsQueryable());
        }