private string GetInsertFullSql() { Type t = this.GetType(); if (!_InsertSqlCache.ContainsKey(t)) { EntityMeta metadeta = EntityReflect.GetDefineInfoFromType(t); string sql = SQLBuilder.BuildInsertSql(metadeta); lock (lockobject) { if (!_InsertSqlCache.ContainsKey(t)) { _InsertSqlCache.Add(t, sql); } } } return(_InsertSqlCache[t]); }
public static EntityMeta GetDefineInfoFromType(Type type) { EntityMeta tdefine = null; lock (lockobject) { if (_cache.ContainsKey(type)) { tdefine = _cache[type]; } } if (tdefine != null) { return(tdefine); } else { tdefine = new EntityMeta(); } var typeInfo = type.GetTypeInfo(); var tableAttribute = typeInfo.GetCustomAttribute <TableNameAttribute>(); tdefine.TableName = tableAttribute != null ? tableAttribute.TableName : type.FullName.Split('.').Last(); PropertyInfo[] pinfos = type.GetProperties(); foreach (PropertyInfo p in pinfos) { var attrs = p.GetCustomAttributes(); EntityColumnMeta ecmeta = new EntityColumnMeta { ColumnName = p.Name }; ecmeta.PropertyName = p.Name; foreach (Attribute cusattr in attrs) { if (cusattr is IgnoreAttribute) { ecmeta = null; break; } if (cusattr is PrimaryKeyAttribute) { ecmeta.PrimaryKey = true; } if (cusattr is MapFieldAttribute) { ecmeta.ColumnName = ((MapFieldAttribute)cusattr).MapFieldName; } if (cusattr is IdentityAttribute) { ecmeta.Identity = true; } if (cusattr is NullableAttribute) { ecmeta.Nullable = true; } } if (ecmeta != null) { tdefine.Columns.Add(ecmeta); } } lock (lockobject) { if (!_cache.ContainsKey(type)) { _cache.Add(type, tdefine); } } return(tdefine); }
private string GetUpdateChangeColumnsSql() { EntityMeta metadeta = EntityReflect.GetDefineInfoFromType(this.GetType()); return(SQLBuilder.BuildUpdateSql(metadeta, this._PropertyChangedList)); }