// --------------------------------------------------------------------- // Insert // --------------------------------------------------------------------- public void Insert <T>(T model, String statement, IInsertable <T> traits) { using (SqlCommand cmd = new SqlCommand(statement, m_connection)) { traits.ApplyInsert(model, cmd); cmd.ExecuteNonQuery(); } }
public Task <T> ExecuteReturnEntityAsync() { Task <T> result = new Task <T>(() => { IInsertable <T> asyncInsertable = CopyInsertable(); return(asyncInsertable.ExecuteReturnEntity()); }); TaskStart(result); return(result); }
public Task <long> ExecuteReturnBigIdentityAsync() { Task <long> result = new Task <long>(() => { IInsertable <T> asyncInsertable = CopyInsertable(); return(asyncInsertable.ExecuteReturnBigIdentity()); }); result.Start(); return(result); }
/// <summary> /// 插入一个实体 /// </summary> /// <typeparam name="T">表实体</typeparam> /// <param name="entity">实体内容</param> /// <param name="pk">要忽略的主键</param> /// <returns>本批次最大主键ID</returns> public long Add <T>(T[] entitys, Expression <Func <T, object> > pk = null) where T : class, new() { IInsertable <T> r = _db.Insertable(entitys); if (pk != null) { r = r.IgnoreColumns(pk); } return(r.ExecuteReturnIdentity()); }
public Task <bool> ExecuteCommandIdentityIntoEntityAsync() { Task <bool> result = new Task <bool>(() => { IInsertable <T> asyncInsertable = CopyInsertable(); return(asyncInsertable.ExecuteCommandIdentityIntoEntity()); }); result.Start(); return(result); }
public Task <int> ExecuteCommandAsync() { Task <int> result = new Task <int>(() => { IInsertable <T> asyncInsertable = CopyInsertable(); return(asyncInsertable.ExecuteCommand()); }); result.Start(); return(result); }
/// <summary> /// 批量新增实体 /// </summary> /// <typeparam name="T">表实体</typeparam> /// <param name="entitys">实体集合,List<T></param> /// <param name="ignorePk">要忽略的主键</param> /// <returns>最大id</returns> public long Insert <T>(T[] entitys, Expression <Func <T, object> > ignorePk = null) where T : class, new() { IInsertable <T> insertObj = _db.Insertable(entitys); if (ignorePk != null) { insertObj = insertObj.IgnoreColumns(ignorePk); } var t = insertObj.ExecuteReturnBigIdentityAsync(); t.Wait(); return(t.Result); }
public int Insert <T>(T entity, Expression <Func <T, object> > pk = null, bool isIdentity = true) where T : class, new() { IInsertable <T> insertObj = _db.Insertable(entity); if (pk != null) { insertObj = insertObj.IgnoreColumns(pk); } if (isIdentity) { return(insertObj.ExecuteReturnIdentity()); } return(insertObj.ExecuteCommand()); }
/// <summary> /// 设置需新增的字段和值 /// </summary> /// <param name="source">source</param> /// <param name="property">字段</param> /// <param name="value">值</param> public static IInsertable Set(this IInsertable source, MemberExpression property, object value) { var key = source.Properties.Keys.Where(s => s.MemberExpressionEqual(property)).FirstOrDefault(); if (key == null) { source.Properties.Add(property, value); } else { source.Properties[key] = value; } return(source); }
/** * Create a new {@code AnimateAdditionAdapter} with given {@link android.widget.BaseAdapter}. * * @param baseAdapter should implement {@link Insertable}, * or be a {@link com.nhaarman.listviewanimations.BaseAdapterDecorator} whose BaseAdapter implements the interface. */ public AnimateAdditionAdapter(BaseAdapter baseAdapter) : base(baseAdapter) { //super(baseAdapter); BaseAdapter rootAdapter = getRootAdapter(); if (!(rootAdapter is IInsertable)) { throw new Java.Lang.IllegalArgumentException("BaseAdapter should implement Insertable!"); } //mInsertable = (Insertable<T>) rootAdapter; mInsertable = (IInsertable)rootAdapter; mInsertQueue = new InsertQueue <T>(mInsertable); }
/// <summary> /// 设置需新增的字段和值 /// </summary> /// <param name="source"></param> /// <param name="property">字段</param> /// <param name="value">值</param> /// <typeparam name="T">元素类型</typeparam> public static IInsertable <T> Set <T>(this IInsertable <T> source, Expression <Func <T, object> > property, object value) { MemberExpression me = property.Body.ToMemberExpression(); var key = source.Properties.Keys.Where(s => s.MemberExpressionEqual(me)).FirstOrDefault(); if (key == null) { source.Properties.Add(me, value); } else { source.Properties[key] = value; } return(source); }
// --------------------------------------------------------------------- // Insert // --------------------------------------------------------------------- public void Insert <T>(T model, String statement, IInsertable <T> traits) { using (IDbCommand command = m_connection.CreateCommand()) { command.CommandText = statement; traits.ApplyInsert(model, command); command.ExecuteNonQuery(); } IAutoNumberable <T> anTraits = traits is IAutoNumberable <T> ?traits as IAutoNumberable <T> : Orm.GetAutoNumberable <T>() ; if (anTraits != null) { anTraits.ApplyAutoNumber(model, GetLastInsertRowId()); } }
/// <summary> /// 将实体对象插入到数据库 /// </summary> /// <param name="object">实体对象</param> public virtual int Insert(object @object) { IEntityObject entity = (IEntityObject)@object; Type elementType = @object.GetType().BaseType; IInsertable insertable = this.factory.CreateInsertProvider(this).CreateInsert(elementType); var properties = @object.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); properties.Where(property => property.IsAutoIncrease() == false).Each(property => { if (entity.ChangedProperties.Contains(property.Name)) { ParameterExpression pe = Expression.Parameter(@object.GetType(), "s"); MemberExpression me = Expression.MakeMemberAccess(pe, property); insertable.Set(me, property.EmitGetValue(@object)); } }); return(insertable.Execute(elementType)); }
public InsertQueue(IInsertable insertable) { mInsertable = insertable; }
/// <summary> /// 添加单个 /// </summary> /// <param name="entity">实体</param> /// <returns>主键ID</returns> public virtual async Task <bool> Add(T entity) { IInsertable <T> insert = this.SugarClient.Insertable(entity); return(await insert.ExecuteCommandIdentityIntoEntityAsync()); }
public void Insert <T>(T model, IInsertable <T> traits) { Insert(model, traits.InsertSql(), traits); }
public static void RegisterInsert <T>(IInsertable <T> converter) { Init(); m_insert_register[typeof(T)] = converter; }
/// <summary> /// 执行指定类型元素的删除操作 /// </summary> /// <param name="source">可新增的对象</param> /// <typeparam name="T">受影响的行数</typeparam> public static int Execute <T>(this IInsertable <T> source) { return(source.Provider.Execute <T>(source.Properties)); }
/// <summary> /// 执行未指定元素类型的插入操作 /// </summary> /// <param name="source">Source.</param> /// <param name="elementType">Element type.</param> public static int Execute(this IInsertable source, Type elementType) { return(source.Provider.Execute(elementType, source.Properties)); }
public static IDelete Delete <TSource>(this IInsertable <TSource> source, TSource entity, params TSource[] entities) { return(new DeleteStatement(((ISourcable)source).GetDatabase(), entity, entities)); }
public static IInsert InsertFrom <TSource>(this IInsertable <TSource> source, IQuery <TSource> from) { return(new InsertFromStatement <TSource>(((ISourcable)source).GetDatabase(), from)); }
public void Add(IInsertable insertable) { _buffer.Post(insertable); }
/// <summary> /// /// </summary> /// <param name="able"></param> public SugarWInsertable(IInsertable <T> able) { _insertable = able; }