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); }
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()); }
public StringBuilder BuildCreateTableColumns(IObjectMapInfo map) { map.ThrowIfNullArgument(nameof(map)); _map = map; _str = new StringBuilder(); BuildCreateTableColumns(); return(_str); }
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(); }
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); }
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()); }
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; }
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; }
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); }
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>(); } }
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); }
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); }
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; }
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); }
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); }
public void SetMapInfo(Type entityType, IObjectMapInfo info) { _log.WarningIf(_cache.ContainsKey(entityType), "Entity type [{0}] mapping information is overrided!.", entityType); _cache[entityType] = info; }
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; }