Beispiel #1
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());
        }
Beispiel #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 = job[i].Name;

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

            sb.Clear();

            temp = temp[0..(temp.Length - 2)];
Beispiel #3
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);
        }