示例#1
0
        protected T Create <T>(T obj) where T : class, new()
        {
            using (var context = new LibraryContextMemory(_configuration))
            {
                context.Add <T>(obj);
                context.SaveChanges();
            }

            if (CreatedEntities.ContainsKey(typeof(T).Name))
            {
                var value = CreatedEntities[typeof(T).Name];
                value.Add(obj);
            }
            else
            {
                CreatedEntities.Add(typeof(T).Name, new List <object> {
                    obj
                });
            }
            return(obj);
        }
示例#2
0
        protected virtual T Create <T>(Action <T> predicate = null) where T : class, new()
        {
            var obj = new T();

            predicate?.Invoke(obj);
            using (LibraryContextMemory context = new LibraryContextMemory(_configuration))
            {
                context.Add <T>(obj);
                context.SaveChanges();
            }

            if (CreatedEntities.ContainsKey(typeof(T).Name))
            {
                var value = CreatedEntities[typeof(T).Name];
                value.Add(obj);
            }
            else
            {
                CreatedEntities.Add(typeof(T).Name, new List <object> {
                    obj
                });
            }
            return(obj);
        }