コード例 #1
0
        public static async Task BulkInsertWithIdGeneration <T>(this IContextAdapter contextAdapter, IList <T> forSave)
            where T : class
        {
            if (forSave == null)
            {
                return;
            }

            var pk = contextAdapter.GetPk <T>();

            if (!pk.IsIdentity)
            {
                await contextAdapter.BulkInsert(forSave, true);
            }
            else
            {
                var isNew      = ExpressHelper.IsPropertyEmpty <T>(pk.PropertyName, pk.Type).Compile();
                var newObjects = forSave.Where(isNew).ToArray();
                if (!newObjects.Any())
                {
                    return;
                }

                await contextAdapter.RetrieveIds(newObjects);

                await contextAdapter.BulkInsert(newObjects, true);
            }
        }
コード例 #2
0
        private Action <TSource, TDestination> GetCopyPk(IContextAdapter contextAdapter)
        {
            var expression = ExpressHelper.CreateCopy <TSource, TDestination>(
                contextAdapter.GetPk <TSource>().PropertyName,
                contextAdapter.GetForwardKeyProperty <TDestination>(_propertyName, typeof(TSource)));

            return(expression.Compile());
        }
コード例 #3
0
        private Action <TSource, TSource> GetCopyPk(IContextAdapter contextAdapter)
        {
            var path         = ExpressHelper.GetPath(_extractor);
            var propertyName = contextAdapter.GetBackwardKeyProperty <TSource>(path);
            var expression   = ExpressHelper.CreateCopy <TSource, TSource>(
                $"{path}.{contextAdapter.GetPk<TSource>().PropertyName}", propertyName);

            return(expression.Compile());
        }
コード例 #4
0
        public async Task RetrieveIdsLong <TEntity>(IContextAdapter context, TEntity[] entities)
        {
            var tableName = context.GetTableName <TEntity>();

            var entitiesLength = entities.Length;
            var minId          = Minus(await context.RunScalar <TValue>(RetrieveIdsSql(tableName, entitiesLength)), entitiesLength);
            var pkSetter       = ExpressHelper.GetPropSetter <TEntity, TValue>(context.GetPk <TEntity>().PropertyName).Compile();
            var id             = minId;

            foreach (var entity in entities)
            {
                id = AddOne(id);
                pkSetter(entity, id);
            }
        }
コード例 #5
0
 public static async Task RetrieveIds <TEntity>(this IContextAdapter contextAdapter, TEntity[] entities)
     where TEntity : class
 {
     await Worker[contextAdapter.GetPk <TEntity>().Type].RetrieveIdsLong(contextAdapter, entities);
 }