/// <summary> /// Builds and executes insert statement /// </summary> public virtual void Insert <T, TY>(Dwarf <TY> dwarf, Guid?customId = null) where TY : Dwarf <TY>, new() { var type = DbContextHelper <T> .ClearCacheForType(DwarfHelper.DeProxyfy(dwarf)); dwarf.Id = customId ?? Guid.NewGuid(); ExecuteNonQuery <T, TY>(new QueryBuilder <T>().InsertInto(type).Values(dwarf)); dwarf.IsSaved = true; }
/// <summary> /// Builds and executes an update statement /// </summary> public virtual void Update <T>(Dwarf <T> dwarf, IEnumerable <ExpressionProperty> properties) where T : Dwarf <T>, new() { var type = DbContextHelper <T> .ClearCacheForType(DwarfHelper.DeProxyfy(dwarf)); var command = new QueryBuilder <T>() .Update(type) .Set(dwarf, properties) .Where(dwarf, Cfg.PKProperties[type]); ExecuteNonQuery <T>(command); }
/// <summary> /// Builds and executes a delete statement /// </summary> public virtual void Delete <T>(Dwarf <T> dwarf) where T : Dwarf <T>, new() { var type = DbContextHelper <T> .ClearCacheForType(DwarfHelper.DeProxyfy(dwarf)); var command = new QueryBuilder <T>() .DeleteFrom <T>() .Where(dwarf, Cfg.PKProperties[type]); ExecuteNonQuery <T>(command); dwarf.IsSaved = false; }
/// <summary> /// Returns the ManyToMany table name for the supplied criteria /// </summary> public static string GetTableName <T>(Expression <Func <T, object> > exp) { var pi = PropertyHelper.GetProperty(DwarfHelper.DeProxyfy(typeof(T)), ReflectionHelper.GetPropertyName(exp)); return(GetTableName(typeof(T), pi.ContainedProperty)); }