Ejemplo n.º 1
0
        public virtual StringBuilder BuildInsertValues(IObjectMapInfo map, object entity)
        {
            StringBuilder b = new StringBuilder();
            IReflector    r = Reflector.Bind(entity);

            foreach (var pmi in map.PropertyMaps)
            {
                if (map.PrimaryKeyGenerate == PrimaryKeyGenerate.Auto && map.PrimaryKeyMaps.Contains(pmi))
                {
                    continue;
                }

                //Note:special handling Guid when insert, must use '*', not same as WHERE {Guid{*}}
                object val = r.GetPropertyValue(pmi.PropertyName);
                if (val is Guid)
                {
                    b.Append(_tr.GetValueString(val.ToString())).Append(_tr.ColumnDelimiter);
                }
                else
                {
                    b.Append(_tr.GetValueString(val)).Append(_tr.ColumnDelimiter);
                }
            }
            b.RemoveEnd(_tr.ColumnDelimiter);
            return(b);
        }
Ejemplo n.º 2
0
        public StringBuilder BuildCreateTableColumns(IObjectMapInfo map)
        {
            map.ThrowIfNullArgument(nameof(map));

            _map = map;
            _str = new StringBuilder();
            BuildCreateTableColumns();
            return _str;
        }
 public string Translate(Expression expression, IObjectMapInfo mapInfo)
 {
     mapInfo.ThrowIfNullArgument(nameof(mapInfo));
     expression.ThrowIfNullArgument(nameof(expression));
     _map = mapInfo;
     _str = new StringBuilder();
     this.Visit(expression);
     return(_str.ToString());
 }
Ejemplo n.º 4
0
        public StringBuilder BuildCreateTableColumns(IObjectMapInfo map)
        {
            map.ThrowIfNullArgument(nameof(map));

            _map = map;
            _str = new StringBuilder();
            BuildCreateTableColumns();
            return(_str);
        }
Ejemplo n.º 5
0
 public virtual StringBuilder BuildSelectColumns(IObjectMapInfo map)
 {
     StringBuilder b = new StringBuilder();
     foreach (var pmi in map.PropertyMaps)
     {
         b.Append(_tr.GetEscapedColumnName(pmi.ColumnName)).Append(_tr.ColumnDelimiter);
     }
     b.RemoveEnd(_tr.ColumnDelimiter);
     return b;
 }
 public virtual string Translate(Expression expression, IObjectMapInfo map)
 {
     expression.ThrowIfNullArgument(nameof(expression));
     map.ThrowIfNullArgument(nameof(map));
     _map = map;
     this._str = new StringBuilder();
     this.Visit(expression);
     if (this._str.BracketedBy(StringPair.Parenthesis))
         this._str.UnBracketing(StringPair.Parenthesis);
     return this._str.ToString();
 }
Ejemplo n.º 7
0
        public virtual StringBuilder BuildSelectColumns(IObjectMapInfo map)
        {
            StringBuilder b = new StringBuilder();

            foreach (var pmi in map.PropertyMaps)
            {
                b.Append(_tr.GetEscapedColumnName(pmi.ColumnName)).Append(_tr.ColumnDelimiter);
            }
            b.RemoveEnd(_tr.ColumnDelimiter);
            return(b);
        }
Ejemplo n.º 8
0
 private static bool IsNull(DataRow dr, string alias, IObjectMapInfo map)
 {
     foreach (var pmi in map.PrimaryKeyMaps)
     {
         object val = dr[alias + pmi.ColumnName];
         if (val != DBNull.Value)
         {
             return(false);
         }
     }
     return(true);
 }
 public virtual string Translate(Expression expression, IObjectMapInfo map)
 {
     expression.ThrowIfNullArgument(nameof(expression));
     map.ThrowIfNullArgument(nameof(map));
     _map      = map;
     this._str = new StringBuilder();
     this.Visit(expression);
     if (this._str.BracketedBy(StringPair.Parenthesis))
     {
         this._str.UnBracketing(StringPair.Parenthesis);
     }
     return(this._str.ToString());
 }
Ejemplo n.º 10
0
 public virtual StringBuilder BuildUpdateSets(IObjectMapInfo map, object entity)
 {
     StringBuilder b = new StringBuilder();
     IReflector r = Reflector.Bind(entity);
     foreach (var pmi in map.NonPKPropertyMaps)
     {
         b.Append(_tr.GetEscapedColumnName(pmi.ColumnName));
         b.Append(_tr.Equal).Append(_tr.GetValueString(r.GetPropertyValue(pmi.PropertyName)));
         b.Append(_tr.ColumnDelimiter);
     }
     b.RemoveEnd(_tr.ColumnDelimiter);
     return b;
 }
Ejemplo n.º 11
0
        public virtual StringBuilder BuildInsertColumns(IObjectMapInfo map, object entity)
        {
            StringBuilder b = new StringBuilder();
            foreach (var pmi in map.PropertyMaps)
            {
                if (map.PrimaryKeyGenerate == PrimaryKeyGenerate.Auto && map.PrimaryKeyMaps.Contains(pmi))
                    continue;

                b.Append(_tr.GetEscapedColumnName(pmi.ColumnName)).Append(_tr.ColumnDelimiter);
            }
            b.RemoveEnd(_tr.ColumnDelimiter);
            return b;
        }
Ejemplo n.º 12
0
        public virtual StringBuilder BuildUpdateSets(IObjectMapInfo map, object entity)
        {
            StringBuilder b = new StringBuilder();
            IReflector    r = Reflector.Bind(entity);

            foreach (var pmi in map.NonPKPropertyMaps)
            {
                b.Append(_tr.GetEscapedColumnName(pmi.ColumnName));
                b.Append(_tr.Equal).Append(_tr.GetValueString(r.GetPropertyValue(pmi.PropertyName)));
                b.Append(_tr.ColumnDelimiter);
            }
            b.RemoveEnd(_tr.ColumnDelimiter);
            return(b);
        }
Ejemplo n.º 13
0
        public virtual string TruncateTable <T>()
        {
            IObjectMapInfo mapInfo = _cache.GetMapInfo(typeof(T), true);

            try
            {
                StringBuilder str = new StringBuilder();
                str.Append(_tr.TruncateTable).Append(_tr.GetEscapedTableName(mapInfo.Table.LocalName));
                return(str.ToString());
            }
            catch (Exception ex)
            {
                throw ex.CreateWrapException <SQLGenerateException>();
            }
        }
Ejemplo n.º 14
0
        public virtual StringBuilder BuildInsertColumns(IObjectMapInfo map, object entity)
        {
            StringBuilder b = new StringBuilder();

            foreach (var pmi in map.PropertyMaps)
            {
                if (map.PrimaryKeyGenerate == PrimaryKeyGenerate.Auto && map.PrimaryKeyMaps.Contains(pmi))
                {
                    continue;
                }

                b.Append(_tr.GetEscapedColumnName(pmi.ColumnName)).Append(_tr.ColumnDelimiter);
            }
            b.RemoveEnd(_tr.ColumnDelimiter);
            return(b);
        }
Ejemplo n.º 15
0
        public override IPropertyMapInfo GetPrimaryKeyNeedBinding <T>()
        {
            IObjectMapInfo map = _cache.GetMapInfo(typeof(T), true);

            if (map.PrimaryKeyGenerate == PrimaryKeyGenerate.Customized && map.PKGenerateString.StartsWith(ConstantString.SEQ_Prefix))
            {
                if (map.PKStatus == PrimaryKeyStatus.Single)
                {
                    return(map.PrimaryKeyMaps.First());
                }
                else
                {
                    GenerateExceptionHelper.ThrowPrimaryKeyDefineNotSupport(typeof(T));
                }
            }

            return(null);
        }
Ejemplo n.º 16
0
        public virtual StringBuilder BuildInsertValues(IObjectMapInfo map, object entity)
        {
            StringBuilder b = new StringBuilder();
            IReflector r = Reflector.Bind(entity);
            foreach (var pmi in map.PropertyMaps)
            {
                if (map.PrimaryKeyGenerate == PrimaryKeyGenerate.Auto && map.PrimaryKeyMaps.Contains(pmi))
                    continue;

                //Note:special handling Guid when insert, must use '*', not same as WHERE {Guid{*}}
                object val = r.GetPropertyValue(pmi.PropertyName);
                if (val is Guid)
                    b.Append(_tr.GetValueString(val.ToString())).Append(_tr.ColumnDelimiter);
                else
                    b.Append(_tr.GetValueString(val)).Append(_tr.ColumnDelimiter);
            }
            b.RemoveEnd(_tr.ColumnDelimiter);
            return b;
        }
Ejemplo n.º 17
0
        internal static T MapToEntity <T>(this DataRow dr, IObjectMapInfo map, string alias = null)
        {
            if (IsNull(dr, alias, map))
            {
                return(default(T));
            }

            T          entity = Activator.CreateInstance <T>();
            IReflector r      = Reflector.Bind(entity);

            foreach (var pmi in map.PropertyMaps)
            {
                object val = dr[alias + pmi.ColumnName];

                Type propertyType = r.GetPropertyType(pmi.PropertyName);
                if (propertyType.IsEnum)
                {
                    if (val is string)
                    {
                        r.SetPropertyValue(pmi.PropertyName, EnumEx.Parse(propertyType, val as string, false));
                    }
                    else
                    {
                        r.SetPropertyValue(pmi.PropertyName, EnumEx.Parse(propertyType, (int)System.Convert.ChangeType(val, typeof(int))));
                    }
                }
                else
                {
                    if (val is System.DBNull)
                    {
                        r.SetPropertyValue(pmi.PropertyName, null);
                    }
                    else
                    {
                        r.SetPropertyValue(pmi.PropertyName, TypeCast.ChangeToTypeOrNullableType(val, propertyType));
                    }
                }
            }

            return(entity);
        }
Ejemplo n.º 18
0
        public virtual StringBuilder BuildWherePrimaryKey(IObjectMapInfo map, object entity)
        {
            StringBuilder b = new StringBuilder();
            IReflector    r = Reflector.Bind(entity);

            foreach (var pki in map.PrimaryKeyMaps)
            {
                b.Append(_tr.GetEscapedColumnName(pki.ColumnName));
                object right = r.GetPropertyValue(pki.PropertyName);
                if (right == null)
                {
                    b.Append(_tr.Is);
                }
                else
                {
                    b.Append(_tr.Equal);
                }
                b.Append(_tr.GetValueString(right));
                b.Append(_tr.And);
            }
            b.RemoveEnd(_tr.And);
            return(b);
        }
Ejemplo n.º 19
0
        public void SetMapInfo(Type entityType, IObjectMapInfo info)
        {
            _log.WarningIf(_cache.ContainsKey(entityType), "Entity type [{0}] mapping information is overrided!.", entityType);

            _cache[entityType] = info;
        }
Ejemplo n.º 20
0
        public void SetMapInfo(Type entityType, IObjectMapInfo info)
        {
            _log.WarningIf(_cache.ContainsKey(entityType), "Entity type [{0}] mapping information is overrided!.", entityType);

            _cache[entityType] = info;
        }
Ejemplo n.º 21
0
 public virtual StringBuilder BuildWherePrimaryKey(IObjectMapInfo map, object entity)
 {
     StringBuilder b = new StringBuilder();
     IReflector r = Reflector.Bind(entity);
     foreach (var pki in map.PrimaryKeyMaps)
     {
         b.Append(_tr.GetEscapedColumnName(pki.ColumnName));
         object right = r.GetPropertyValue(pki.PropertyName);
         if (right == null)
             b.Append(_tr.Is);
         else
             b.Append(_tr.Equal);
         b.Append(_tr.GetValueString(right));
         b.Append(_tr.And);
     }
     b.RemoveEnd(_tr.And);
     return b;
 }