private Entities.Type _ensureTypeCreated()
        {
            var className = typeof(T).FullName;
            var item      = _context.Types
                            .Include(x => x.Attributes)
                            .SingleOrDefault(x => x.Name == className);

            if (item != null)
            {
                return(item);
            }

            //create type and attributes
            item = new Entities.Type()
            {
                Name = className
            };
            _context.Types.Add(item);

            var props = typeof(T)
                        .GetProperties();
            var attributes = typeof(T)
                             .GetProperties()
                             .Where(x => x.Name.ToLower() != "id")
                             .Select(x => new Entities.Attribute()
            {
                Name = x.Name, Type = item
            })
                             .ToArray();

            //save metadata
            _context.Attributes.AddRange(attributes);
            _context.SaveChanges();
            return(item);
        }
        private void _saveNew(T entity, Entities.Type type)
        {
            var obj = new Entities.Object()
            {
                Type = type
            };

            _context.Objects.Add(obj);
            entity.Id = obj.Id;
            foreach (var attribute in type.Attributes)
            {
                object attrVal = entity.GetType().GetProperty(attribute.Name).GetValue(entity);
                var    value   = new Value()
                {
                    Attribute = attribute,
                    Data      = Converter.StringFromObject(attrVal),
                    Object    = obj
                };
                _context.Values.Add(value);
            }
            _context.SaveChanges();
        }