public static GXDeleteArgs Delete <T>(Expression <Func <T, object> > where) { GXDeleteArgs arg = DeleteAll <T>(); if (where != null) { arg.Where.Or <T>(where); } return(arg); }
public static GXDeleteArgs DeleteRange <T>(IEnumerable <T> collection) { if (!collection.GetEnumerator().MoveNext()) { throw new ArgumentOutOfRangeException("DeleteRange failed. Collection is empty."); } GXDeleteArgs args = Delete(typeof(T)); args.Parent.Updated = true; args.Where.Or <T>(q => collection); return(args); }
public static GXDeleteArgs Delete <T>(T item) { if (item == null) { throw new ArgumentNullException("Removed item can't be null."); } if (item is IEnumerable) { GXDeleteArgs arg = Delete(GXInternal.GetPropertyType(typeof(T))); foreach (var it in item as IEnumerable) { arg.Where.Or <T>(q => it); } return(arg); } return(Delete <T>(q => item)); }
public static GXDeleteArgs DeleteById <T>(object id) { if (id == null) { throw new ArgumentNullException("Invalid Id."); } GXDeleteArgs arg = DeleteAll <T>(); GXSerializedItem si = GXSqlBuilder.FindUnique(typeof(T)); if (si == null) { throw new Exception("DeleteById failed. Class is not derived from IUnique."); } string name = GXDbHelpers.GetColumnName(si.Target as PropertyInfo, '\0'); arg.Where.Or <IUnique <T> >(q => name.Equals(id)); return(arg); }
public static GXDeleteArgs Remove <TItem, TDestination>(TItem[] items, TDestination[] collections) { object collectionId, id; if (items == null || collections == null || items.Length == 0 || collections.Length == 0) { throw new ArgumentNullException("Invalid value"); } Type itemType = typeof(TItem); Type collectionType = typeof(TDestination); GXSerializedItem si = GXSqlBuilder.FindRelation(itemType, collectionType); if (si.Relation == null || si.Relation.RelationMapTable == null) { throw new ArgumentNullException("Invalid collection"); } GXDeleteArgs args = Delete(si.Relation.RelationMapTable.Relation.PrimaryTable); args.Parent.Updated = true; GXSerializedItem siItem = GXSqlBuilder.FindRelation(collectionType, itemType); foreach (TDestination c in collections) { //Get collection id. collectionId = si.Relation.RelationMapTable.Relation.ForeignId.Get(c); foreach (TItem it in items) { object target = GXJsonParser.CreateInstance(si.Relation.RelationMapTable.Relation.PrimaryTable); si.Relation.RelationMapTable.Relation.PrimaryId.Set(target, collectionId); //Get item id. id = siItem.Relation.RelationMapTable.Relation.ForeignId.Get(it); siItem.Relation.RelationMapTable.Relation.PrimaryId.Set(target, id); Expression <Func <object, object> > t = q => target; args.Where.List.Add(new KeyValuePair <WhereType, LambdaExpression>(WhereType.Or, t)); } } return(args); }