public static ProfileStorage Create <T>(TypeNameWithoutVersion key, T item)
        {
            var profileStorage = new ProfileStorage(key);

            profileStorage.SetValue(item);
            return(profileStorage);
        }
		public object this[Type type]
		{
			get
			{
				var key = ProfileStorage.Key(type);
				var profileStorage = _persister.FindBy(_profileId, key).FirstOrDefault();
				return profileStorage != null ? profileStorage.GetValue() : null;
			}
			set
			{
				if (value == null)
					return;

				var key = ProfileStorage.Key(value.GetType());
				var valueStorage = _persister.FindBy(_profileId, key).FirstOrDefault();

				if (valueStorage != null)
				{
					valueStorage.SetValue(value);
					_persister.Update(valueStorage);
				}
				else
				{
					valueStorage = new ProfileStorage(new TypeNameWithoutVersion(value.GetType())) {ProfileId = _profileId.Value};
					valueStorage.SetValue(value);
					_persister.Insert(valueStorage);
				}
			}
		}
        public object this[Type type]
        {
            get
            {
                var key            = ProfileStorage.Key(type);
                var profileStorage = _persister.FindBy(_profileId, key).FirstOrDefault();
                return(profileStorage != null?profileStorage.GetValue() : null);
            }
            set
            {
                if (value == null)
                {
                    return;
                }

                var key          = ProfileStorage.Key(value.GetType());
                var valueStorage = _persister.FindBy(_profileId, key).FirstOrDefault();

                if (valueStorage != null)
                {
                    valueStorage.SetValue(value);
                    _persister.Update(valueStorage);
                }
                else
                {
                    valueStorage = new ProfileStorage(new TypeNameWithoutVersion(value.GetType()))
                    {
                        ProfileId = _profileId.Value
                    };
                    valueStorage.SetValue(value);
                    _persister.Insert(valueStorage);
                }
            }
        }
		public void ShouldStoreAndRetrieveRecord()
		{
			var profileStorage = new ProfileStorage {ProfileId = _profile.Id, ValueKey = "value key"};
			profileStorage.SetValue("my value");
			_persister.Insert(profileStorage);

			var retrieved = _persister.FindBy(_profile.Id).Single();

			retrieved.Should(Be.EqualTo(profileStorage).Using<ProfileStorage>(Compare));
		}
        private ProfileStorage ConvertToProfileStorage(T value)
        {
            var result = new ProfileStorage(_key)
            {
                ProfileId = _profileId.Value
            };

            result.SetValue(value);
            return(result);
        }
        public void ShouldDeleteByNameWhenNameContainsSpecialCharacters()
        {
            var profileStorage = new ProfileStorage { ProfileId = _profile.Id, ValueKey = "value key", Name = "'test" };
            profileStorage.SetValue("my value");
            _persister.Insert(profileStorage);

            _persister.Delete(_profile.Id, profileStorage.ValueKey, profileStorage.Name);
            _persister.Contains(profileStorage.Name, _profile.Id, profileStorage.ValueKey, profileStorage.GetValue()).Should(
                Be.False);
        }
		public void Update(params ProfileStorage[] profileStorages)
		{
			using (var context = CreateContext())
			{
				foreach (var profileStorage in profileStorages)
				{
					var updatedProfileStorage = new ProfileStorage(new TypeNameWithoutVersion(profileStorage.ValueKey)) { Id = profileStorage.Id, ProfileId = profileStorage.ProfileId, Name = profileStorage.Name};
					context.ProfileStorages.Attach(updatedProfileStorage);
					updatedProfileStorage.SetValue(profileStorage.GetValue());
				}

				Flush(context);
			}
		}
        public void Update(params ProfileStorage[] profileStorages)
        {
            using (var context = CreateContext())
            {
                foreach (var profileStorage in profileStorages)
                {
                    var updatedProfileStorage = new ProfileStorage(new TypeNameWithoutVersion(profileStorage.ValueKey))
                    {
                        Id = profileStorage.Id, ProfileId = profileStorage.ProfileId, Name = profileStorage.Name
                    };
                    context.ProfileStorages.Attach(updatedProfileStorage);
                    updatedProfileStorage.SetValue(profileStorage.GetValue());
                }

                Flush(context);
            }
        }
		private ProfileStorage[] CreateProfileStorages()
		{
			var profileStorage = new ProfileStorage {ProfileId = _profile.Id, ValueKey = "value key", Name = "Name"};
			profileStorage.SetValue("my value");
			var profileStorage1 = new ProfileStorage {ProfileId = _profile.Id, ValueKey = "value key1", Name = "Name"};
			profileStorage1.SetValue("my value1");

			var profileStorage2 = new ProfileStorage {ProfileId = _profile.Id, ValueKey = "value key2", Name = "Name2"};
			profileStorage2.SetValue("my value2");

			var profileStorages = new[] {profileStorage, profileStorage1, profileStorage2};
			_persister.Insert(profileStorages);
			return profileStorages;
		}