Question. Validating nested collections and proceeding only when everything went successfully.
See original GitHub issueThis is a cross post from SO. I’ve got the following DTOs:
public class DatumDto
{
public int Year { get; set; }
public decimal Value { get; set; }
}
public class UpdateDataDto
{
public int Id { get; set; }
public IEnumerable<DatumDto> TimeSeries { get; set; }
}
And the following domain classes.
public class Datum
{
public int Year { get; }
public decimal Value { get; }
public static Validation<Error, Datum> Of (int year, decimal value)
{
// ... logic
return new Datum(year, value)
}
}
public class Data
{
public int Id { get; }
public IEnumerable<Datum> TimeSeries { get; }
public Validation<Error, Data> UpdateTimeSeries(IEnumerable<Datum> timeSeries)
{
// ... logic
}
}
I’ve stripped some code out to have less clutter and focus on what matters to me.
Now my use case is very simple. I need to load Data
with TimeSeries
entities from the database and then execute a command against them, otherwise return all errors to the client.
My command looks as follows:
public class UpdateDataCommand
{
public Validation<Error, int> Execute(IEnumerable<UpdateDataDto> arguments)
{
var data = _repository.Get(arguments.Map(s => s.Id));
// part I am struggling at
// before making any actual changes, I have to validate whether ALL DatumDtos ar valid Datums
// If all of them are valid within all arguments - I should proceed, otherwise gather all faulty Dtos and bring them back.
// I've come here, but it does not compile
var result =
from d in data
join arg in arguments on d.Id equals arg.Id
from datum in arg.TimeSeries
from validation in Domain.Datum.Of(datum.Year, datum.Value)
select d.UpdateTimeSeries(validation); // this does not compile
}
}
How would I go about validation whether all DatumDtos are valid within each element in arguments collection and only proceeding when everything went fine and gather all errors if something has gone wrong?
I understand this might be something trivial, but it’s not yet clicking to me. I’d appreciate help.
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (7 by maintainers)
Top Results From Across the Web
Javax validation on nested objects - not working
If I use the @Valid annotation on the building property, it would validate all of its fields, but for this case I only...
Read more >Nested cross validation for model selection
How do I choose a model from this [outer cross validation] output? Short answer: You don't. Treat the inner cross validation as part...
Read more >Deep nested validation broken · Issue #614
Description When trying to validate nested objects using @ValidateNested(), whitelist: true and forbidNonWhitelisted: true, error "property ...
Read more >Problem with nested object validation · Issue #306
The problem is with class-transformer - you declare an object type, you provide an array and it fails on transform.
Read more >Nested Cross-Validation for Machine Learning with Python
A procedure is required that allows both the models to select well-performing hyperparameters for the dataset and select among a collection ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think a better metric is how many people are watching and who is watching the
language-ext
tag. I think @louthy watches that tag. I used to watch it but no longer do 😢 <— (tear of joy) I think you would have gotten an answer.While @louthy typed you his reply, I typed up this code for you. Like he said, since your example isn’t functional, I am not exactly sure what you want. Nonetheless, here is some code that uses
Sequence
andSeq<>
just like @louthy recommended.Wonderful! Great job.
Your welcome 😃
A failing test case is perfect. Good luck with your future coding!