Пример #1
0
        public T GetOrCreate(IDataContext context, IUniqueIdentifier <ObjectId> forObject = null)
        {
            var id = forObject?.Id ?? "prime:associated-single-doc".GetObjectIdHashCode();

            return(_cache.GetOrAdd(id, (k) =>
            {
                var d = context.As <T>().FirstOrDefault(x => x.Id == k);
                if (d != null)
                {
                    return Emit(d, context, forObject);
                }

                d = new T {
                    Id = k
                };

                (d as IOnNewInstance)?.AfterCreation(context, forObject);

                Emit(d, context, forObject);
                d.Save(context);
                return d;
            }));
        }