private static string FilterSaveFunction(ComputeForNewItemsInfo info, string uniqueSuffix)
        {
            return string.Format(
        @"private static readonly Func<IEnumerable<{0}.{1}>, IEnumerable<{0}.{1}>> _filterSaveComputeForNewItems_{2} =
            {3};

        ",
                info.EntityComputedFrom.Target.Module.Name,
                info.EntityComputedFrom.Target.Name,
                uniqueSuffix,
                info.FilterSaveExpression);
        }
        private static string RecomputeForNewItemsSnippet(ComputeForNewItemsInfo info, string uniqueSuffix)
        {
            DataStructureInfo hookOnSave = info.EntityComputedFrom.Target;
            EntityInfo updatePersistedComputation = info.EntityComputedFrom.Target;

            return string.Format(
            @"if (inserted.Count() > 0)
            {{
                var filter = inserted.Select(item => item.ID).ToArray();
                {4}(filter{3});
            }}
            ",
                hookOnSave.Module.Name,
                hookOnSave.Name,
                uniqueSuffix,
                !string.IsNullOrWhiteSpace(info.FilterSaveExpression) ? (", _filterSaveComputeForNewItems_" + uniqueSuffix) : "",
                EntityComputedFromCodeGenerator.RecomputeFunctionName(info.EntityComputedFrom));
        }
        private static string RecomputeForNewItemsSnippet(ComputeForNewItemsInfo info, string uniqueSuffix)
        {
            DataStructureInfo hookOnSave = info.EntityComputedFrom.Target;
            EntityInfo updatePersistedComputation = info.EntityComputedFrom.Target;

            return string.Format(
            @"            if (inserted.Count() > 0)
            {{
                var filter = inserted.Select(item => item.ID).ToArray();
                {4}(filter{3});

                // Workaround to restore NH proxies after using NHSession.Clear() when saving data in Recompute().
                for (int i=0; i<inserted.Length; i++) inserted[i] = _executionContext.NHibernateSession.Load<{0}.{1}>(inserted[i].ID);
            }}
            ",
                hookOnSave.Module.Name,
                hookOnSave.Name,
                uniqueSuffix,
                !string.IsNullOrWhiteSpace(info.FilterSaveExpression) ? (", _filterSaveComputeForNewItems_" + uniqueSuffix) : "",
                EntityComputedFromCodeGenerator.RecomputeFunctionName(info.EntityComputedFrom));
        }
 private static string GetUniqueSuffixWithinTarget(ComputeForNewItemsInfo info)
 {
     return DslUtility.NameOptionalModule(info.EntityComputedFrom.Source, info.EntityComputedFrom.Target.Module);
 }