mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-04 10:02:40 +01:00
fixed UpdateFields in basic repository.
This commit is contained in:
parent
ccba527e89
commit
eaff6dc18f
@ -101,7 +101,7 @@ public void should_be_able_to_find_object_by_id()
|
||||
|
||||
|
||||
[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 @@ public void update_field_should_only_update_that_filed()
|
||||
childModel.Name = "B";
|
||||
childModel.Interval = 0;
|
||||
|
||||
Subject.UpdateFields(childModel, t => t.Name);
|
||||
Subject.SetFields(childModel, t => t.Name);
|
||||
|
||||
Db.All<JobDefinition>().Single().Type.Should().Be("Address");
|
||||
Db.All<JobDefinition>().Single().Name.Should().Be("B");
|
||||
Db.All<JobDefinition>().Single().Interval.Should().Be(12);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ namespace NzbDrone.Core.Datastore
|
||||
void Purge();
|
||||
bool HasItems();
|
||||
void DeleteMany(IEnumerable<int> ids);
|
||||
void UpdateFields<TKey>(TModel model, Expression<Func<TModel, TKey>> onlyFields);
|
||||
void SetFields(TModel model, params Expression<Func<TModel, object>>[] properties);
|
||||
}
|
||||
|
||||
public class BasicRepository<TModel> : IBasicRepository<TModel> where TModel : ModelBase, new()
|
||||
@ -148,16 +148,19 @@ public bool HasItems()
|
||||
return Count() > 0;
|
||||
}
|
||||
|
||||
public void UpdateFields<TKey>(TModel model, Expression<Func<TModel, TKey>> onlyFields)
|
||||
public void SetFields(TModel model, params Expression<Func<TModel, object>>[] properties)
|
||||
{
|
||||
if (model.Id == 0)
|
||||
{
|
||||
throw new InvalidOperationException("Attempted to updated model without ID");
|
||||
}
|
||||
|
||||
_dataMapper.Update<TModel>(model, m => m.Id == model.Id);
|
||||
|
||||
// _database.UpdateOnly(model, onlyFields, m => m.Id == model.Id);
|
||||
_dataMapper.Update<TModel>()
|
||||
.Where(c => c.Id == model.Id)
|
||||
.ColumnsIncluding(properties)
|
||||
.Entity(model)
|
||||
.Execute();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
@ -43,7 +43,7 @@ public Series FindByTvdbId(int tvdbId)
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user