Ejemplo n.º 1
0
        /// <summary>
        /// 将一组实体对象的更改保存到库。不会更新实体的其他引用属性。
        /// </summary>
        /// <param name="entities">要保存的实体序列。</param>
        public virtual void Save(IEnumerable <TEntity> entities)
        {
            var query = new QuerySet <TEntity>(Provider, null);

#if N35
            query.BatchOperate(entities.Cast <IEntity>().Where(s => s.EntityState == EntityState.Attached), query.CreateInsertExpression());
            query.BatchOperate(entities.Cast <IEntity>().Where(s => s.EntityState == EntityState.Modified), query.CreateUpdateExpression());
            query.BatchOperate(entities.Cast <IEntity>().Where(s => s.EntityState == EntityState.Detached), query.CreateDeleteExpression(true));
#else
            query.BatchOperate(entities.Where(s => s.EntityState == EntityState.Attached), query.CreateInsertExpression());
            query.BatchOperate(entities.Where(s => s.EntityState == EntityState.Modified), query.CreateUpdateExpression());
            query.BatchOperate(entities.Where(s => s.EntityState == EntityState.Detached), query.CreateDeleteExpression(true));
#endif
        }