From eaff6dc18f55b7d3a93336ef645d37a907ffd790 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Tue, 26 Mar 2013 23:16:55 -0700 Subject: [PATCH] fixed UpdateFields in basic repository. --- .../Datastore/ObjectDatabaseFixture.cs | 6 ++---- NzbDrone.Core/Datastore/BasicRepository.cs | 13 ++++++++----- NzbDrone.Core/Tv/EpisodeRepository.cs | Bin 6973 -> 6970 bytes NzbDrone.Core/Tv/SeriesRepository.cs | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs index 6b9cf9d2d..ad84f1078 100644 --- a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs +++ b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs @@ -101,7 +101,7 @@ namespace NzbDrone.Core.Test.Datastore [Test] - public void update_field_should_only_update_that_filed() + public void set_fields_should_only_update_selected_filed() { var childModel = new JobDefinition { @@ -117,14 +117,12 @@ namespace NzbDrone.Core.Test.Datastore childModel.Name = "B"; childModel.Interval = 0; - Subject.UpdateFields(childModel, t => t.Name); + Subject.SetFields(childModel, t => t.Name); Db.All().Single().Type.Should().Be("Address"); Db.All().Single().Name.Should().Be("B"); Db.All().Single().Interval.Should().Be(12); } - - } } diff --git a/NzbDrone.Core/Datastore/BasicRepository.cs b/NzbDrone.Core/Datastore/BasicRepository.cs index 1d6e47a26..02147daa2 100644 --- a/NzbDrone.Core/Datastore/BasicRepository.cs +++ b/NzbDrone.Core/Datastore/BasicRepository.cs @@ -26,7 +26,7 @@ namespace NzbDrone.Core.Datastore void Purge(); bool HasItems(); void DeleteMany(IEnumerable ids); - void UpdateFields(TModel model, Expression> onlyFields); + void SetFields(TModel model, params Expression>[] properties); } public class BasicRepository : IBasicRepository where TModel : ModelBase, new() @@ -148,16 +148,19 @@ namespace NzbDrone.Core.Datastore return Count() > 0; } - public void UpdateFields(TModel model, Expression> onlyFields) + public void SetFields(TModel model, params Expression>[] properties) { if (model.Id == 0) { throw new InvalidOperationException("Attempted to updated model without ID"); } - _dataMapper.Update(model, m => m.Id == model.Id); - - // _database.UpdateOnly(model, onlyFields, m => m.Id == model.Id); + _dataMapper.Update() + .Where(c => c.Id == model.Id) + .ColumnsIncluding(properties) + .Entity(model) + .Execute(); } + } } diff --git a/NzbDrone.Core/Tv/EpisodeRepository.cs b/NzbDrone.Core/Tv/EpisodeRepository.cs index 80b0d5073e6cd2898b9ebadcc37561a90792962a..e66a1adbe15d57b6de9396b90158f2259ee3bc0f 100644 GIT binary patch delta 16 XcmdmMw##gT4G(j0YRP6Np5J@`HXQ~P delta 19 acmdmGw%2Tf4G&vrK}upt>SlYM-+TZ{)(1=g diff --git a/NzbDrone.Core/Tv/SeriesRepository.cs b/NzbDrone.Core/Tv/SeriesRepository.cs index c7b2b0170..cf9b0bd6f 100644 --- a/NzbDrone.Core/Tv/SeriesRepository.cs +++ b/NzbDrone.Core/Tv/SeriesRepository.cs @@ -43,7 +43,7 @@ namespace NzbDrone.Core.Tv public void SetSeriesType(int seriesId, SeriesTypes seriesType) { - UpdateFields(new Series { Id = seriesId, SeriesType = seriesType }, s => s.SeriesType); + SetFields(new Series { Id = seriesId, SeriesType = seriesType }, s => s.SeriesType); } } } \ No newline at end of file