Ejemplo n.º 1
0
        private static MethodInfo UpdatePrimaries(IDbAccessorSlim accessor, IEnumerable <IDbAggregate> aggregates)
        {
            var primaryGetter = GetPrimaryGetter(aggregates.First().GetType());
            var primaries     = aggregates.Select(a => primaryGetter.Invoke(a, null))
                                .Where(p => p != null)
                                .Cast <IDbEntity>()
                                .ToArray();

            accessor.WriteEntities(primaries);

            return(primaryGetter);
        }
Ejemplo n.º 2
0
        private static void UpdateForeigns(IDbAccessorSlim accessor, IEnumerable <IDbAggregate> aggregates, MethodInfo primaryGetter)
        {
            var foreignProperties = GetForeignProperties(aggregates.First().GetType());
            var foreigns          = new List <IDbEntity>();

            foreach (var aggregate in aggregates)
            {
                var primary = primaryGetter.Invoke(aggregate, null);

                foreach (var foreignProperty in foreignProperties)
                {
                    var mappings          = GetForeignMappings(foreignProperty.Item1);
                    var foreignObject     = foreignProperty.Item2.Invoke(aggregate, null);
                    var foreignEnumerable = foreignObject as IEnumerable;

                    if (foreignEnumerable != null)
                    {
                        foreach (var foreign in foreignEnumerable)
                        {
                            UpdateForeign(primary, (IDbEntity)foreign, mappings);

                            foreigns.Add((IDbEntity)foreign);
                        }
                    }
                    else
                    {
                        var foreign = (IDbEntity)foreignObject;

                        UpdateForeign(primary, foreign, mappings);

                        foreigns.Add(foreign);
                    }
                }
            }

            accessor.WriteEntities(foreigns);
        }