Beispiel #1
0
        private void CreateSql()
        {
            SelectDataReader sr      = new SelectDataReader();
            bool             isgroup = false;;
            StringBuilder    select  = new StringBuilder();
            StringBuilder    group   = new StringBuilder();

            if (ID != null)
            {
                select.Append("(" + ID.ColumnName + ") as p_" + ID.Handler.Property.Name);
                group.Append(ID.ColumnName);
                sr.AddProperty(ID);
            }
            foreach (PropertyMapper pm in Properties)
            {
                sr.AddProperty(pm);
                if (select.Length > 0)
                {
                    select.Append(",");
                }

                if (pm.Aggregation != null)
                {
                    if (pm.Aggregation.DISTINCT)
                    {
                        select.Append("(" + pm.Aggregation.Type + "(DISTINCT " + pm.ColumnName + ")) as p_" + pm.Handler.Property.Name);
                    }
                    else
                    {
                        select.Append("(" + pm.Aggregation.Type + "(" + pm.ColumnName + ")) as p_" + pm.Handler.Property.Name);
                    }
                    isgroup = true;
                }
                else
                {
                    select.Append("(" + pm.ColumnName + ") as p_" + pm.Handler.Property.Name);
                    if (group.Length > 0)
                    {
                        group.Append(",");
                    }
                    group.Append(pm.ColumnName);
                }
            }
            sr.Select = "Select " + DISTINCT + select.ToString() + " from {0}";

            mSelectReader.Add(ObjectType, sr);
            if (isgroup)
            {
                sr.Group = group.ToString();
            }
        }
Beispiel #2
0
        internal static object Load(Type type, object id, IConnectinContext cc)
        {
            Mappings.ObjectMapper     om = Mappings.ObjectMapper.GetOM(type);
            Mappings.SelectDataReader sr = om.GetSelectReader(type);
            if (om.ID == null)
            {
                throw new PeanutException(DataMsg.ID_MAP_NOTFOUND);
            }
            Expression exp = new Expression();

            exp.SqlText.Append(om.ID.ColumnName + "=@p1");
            exp.Parameters.Add(new Command.Parameter {
                Name = "p1", Value = id
            });
            return(EntityBase.ExOnListFirst(type, cc, om.GetSelectTable(sr), exp, null, null));
        }
Beispiel #3
0
 public string GetSelectTable(SelectDataReader sr)
 {
     return(string.Format(sr.Select, Table));
 }
Beispiel #4
0
        private SelectDataReader CreateSelectReader(Type type)
        {
            SelectDataReader sr = new SelectDataReader();

            if (type != ObjectType)
            {
                sr.Proxy = true;
            }
            bool            isgroup = false;;
            StringBuilder   select  = new StringBuilder();
            StringBuilder   group   = new StringBuilder();
            PropertyHandler handler = null;

            if (ID != null)
            {
                handler = MatchProperty(ID.Handler.Property, type);
                if (handler != null)
                {
                    select.Append("(" + ID.ColumnName + ") as p_" + ID.Handler.Property.Name);
                    group.Append(ID.ColumnName);
                    sr.AddProperty(ID);
                    sr.ProxyProperties.Add(handler);
                }
            }
            foreach (PropertyMapper pm in Properties)
            {
                handler = MatchProperty(pm.Handler.Property, type);
                if (handler == null)
                {
                    continue;
                }
                sr.ProxyProperties.Add(handler);
                sr.AddProperty(pm);
                if (select.Length > 0)
                {
                    select.Append(",");
                }

                if (pm.Aggregation != null)
                {
                    if (pm.Aggregation.DISTINCT)
                    {
                        select.Append("(" + pm.Aggregation.Type + "(DISTINCT " + pm.ColumnName + ")) as p_" + pm.Handler.Property.Name);
                    }
                    else
                    {
                        select.Append("(" + pm.Aggregation.Type + "(" + pm.ColumnName + ")) as p_" + pm.Handler.Property.Name);
                    }
                    isgroup = true;
                }
                else
                {
                    select.Append("(" + pm.ColumnName + ") as p_" + pm.Handler.Property.Name);
                    if (group.Length > 0)
                    {
                        group.Append(",");
                    }
                    group.Append(pm.ColumnName);
                }
            }
            sr.Select = "Select " + DISTINCT + select.ToString() + " from {0}";
            if (isgroup)
            {
                sr.Group = group.ToString();
            }
            if (sr.Properties.Count == 0)
            {
                throw new PeanutException(string.Format(DataMsg.BOBJ_NOTMATCH_DOBJ, type, ObjectType));
            }
            return(sr);
        }