public virtual string GetUpdateSQL(IStorageObject obj) { StringBuilder builder = new StringBuilder(); DbObjectInfo dbObjectInfo = DbObjectTools.GetDbObjectInfo(obj.GetType()); this.CheckIsView(dbObjectInfo); DynamicPropertyInfo pkDynamicPropertyInfo = DbObjectTools.GetPkDynamicPropertyInfo(dbObjectInfo, true); string[] source = obj.ModifiedValues.Keys.ToArray <string>(); foreach (KeyValuePair <string, DynamicPropertyInfo> pair in dbObjectInfo.DynamicPropertyInfos) { string key = pair.Key; DynamicPropertyInfo info3 = pair.Value; if ((!info3.PrimaryKey && !info3.ReadOnly) && ((!info3.AutoIncrement && (info3.DefaultValue == null)) && source.Contains <string>(key))) { object obj2 = obj.GetValue(info3.PropertyName); string str2 = this.FormatFieldName(info3.DataFieldName); if (builder.Length > 0) { builder.Append(","); } builder.AppendFormat("{0} = {1}", str2, this.FormatValue(obj2, info3.AllowDBNull)); } } object obj3 = obj.GetValue(pkDynamicPropertyInfo.PropertyName); string str3 = this.FormatFieldName(pkDynamicPropertyInfo.DataFieldName) + " = " + this.FormatValue(obj3, false); return(string.Format(this.GetUpdateSqlTemplate(), this.FormatTableOrViewName(dbObjectInfo.TableName), builder.ToString(), str3)); }
public virtual string GetDeleteSQL(IStorageObject obj) { DbObjectInfo dbObjectInfo = DbObjectTools.GetDbObjectInfo(obj.GetType()); this.CheckIsView(dbObjectInfo); DynamicPropertyInfo pkDynamicPropertyInfo = DbObjectTools.GetPkDynamicPropertyInfo(dbObjectInfo, true); object obj2 = obj.GetValue(pkDynamicPropertyInfo.PropertyName); string str = string.Format(" where {0} = {1}", this.FormatFieldName(pkDynamicPropertyInfo.DataFieldName), this.FormatValue(obj2, false)); return(string.Format(this.GetDeleteSqlTemplate(), this.FormatTableOrViewName(dbObjectInfo.TableName), str)); }
public bool RetrieveByKey(IStorageObject obj) { DynamicPropertyInfo pkDynamicPropertyInfo = DbObjectTools.GetPkDynamicPropertyInfo(DbObjectReflector.GetDbObjectInfo(obj.GetType()), true); if (pkDynamicPropertyInfo == null) { throw new ArgumentException("Primary Key Not Found"); } object keyValue = obj.GetValue(pkDynamicPropertyInfo.PropertyName); return(this.Retrieve(obj, pkDynamicPropertyInfo.DataFieldName, keyValue)); }
internal static bool Compare(IStorageObject obj1, IStorageObject obj2) { if (!obj1.GetType().Equals(obj2.GetType())) { return(false); } DbObjectInfo dbObjectInfo = DbObjectReflector.GetDbObjectInfo(obj1.GetType()); foreach (KeyValuePair <string, DynamicPropertyInfo> pair in dbObjectInfo.DynamicPropertyInfos) { object obj3 = obj1.GetValue(pair.Value.PropertyName); object obj4 = obj2.GetValue(pair.Value.PropertyName); if (obj3 != obj4) { return(false); } } return(true); }
public virtual string GetInsertSQL(IStorageObject obj) { DbObjectInfo dbObjectInfo = DbObjectTools.GetDbObjectInfo(obj.GetType()); this.CheckIsView(dbObjectInfo); StringBuilder builder = new StringBuilder(); StringBuilder builder2 = new StringBuilder(); StringBuilder builder3 = new StringBuilder(); DynamicPropertyInfo autoIncrementDynamicPropertyInfo = DbObjectTools.GetAutoIncrementDynamicPropertyInfo(dbObjectInfo); foreach (KeyValuePair <string, DynamicPropertyInfo> pair in dbObjectInfo.DynamicPropertyInfos) { string key = pair.Key; DynamicPropertyInfo info3 = pair.Value; if ((!info3.AutoIncrement && !info3.ReadOnly) && (info3.DefaultValue == null)) { object obj2 = obj.GetValue(info3.PropertyName); string str2 = this.FormatFieldName(info3.DataFieldName); if (builder3.Length > 0) { builder3.Append(","); } if (builder2.Length > 0) { builder2.Append(","); } builder3.Append(str2); builder2.Append(this.FormatValue(obj2, info3.AllowDBNull)); } } builder.AppendFormat(this.GetInsertSqlTemplate(), this.FormatTableOrViewName(dbObjectInfo.TableName), builder3.ToString(), builder2.ToString()); if (autoIncrementDynamicPropertyInfo != null) { builder.Append("select CAST(SCOPE_IDENTITY() AS INT);"); } return(builder.ToString()); }