✅ Shorten data querying line

Hi, how do I shorten this line that's querying for data? Like, instead of putting them into one long line, I'm looking to separate them, is it something like
var cityOneBlock = _context.CityBlocks.Where(x => x.Location == Location.One)
var cityTwoBlock = _context.CityBlocks.Where(x => x.Location == Location.Two)

var cityBlocks = _context.CityBlocks.Where(cityOneBlock || cityTwoBlock).ToList();
var cityOneBlock = _context.CityBlocks.Where(x => x.Location == Location.One)
var cityTwoBlock = _context.CityBlocks.Where(x => x.Location == Location.Two)

var cityBlocks = _context.CityBlocks.Where(cityOneBlock || cityTwoBlock).ToList();
3 Replies
Patrick
Patrick2y ago
The question doesn't really make sense.
var cityBlocks = _context.CityBlocks.Where(x => x.Location == Location.One || x.Location == Location.Two).ToList();
var cityBlocks = _context.CityBlocks.Where(x => x.Location == Location.One || x.Location == Location.Two).ToList();
alternatively, if you really must not have an OR
var locations = new[] { Location.One, Location.Two };
var cityBlocks = _context.CityBlocks.Where(x => locations.Contains(x.Location)).ToList();
var locations = new[] { Location.One, Location.Two };
var cityBlocks = _context.CityBlocks.Where(x => locations.Contains(x.Location)).ToList();
CoreVisional
CoreVisionalOP2y ago
Ahh, this is what I was looking for Thank you, and sorry for the confusing title btw
Accord
Accord2y ago
Closed!
Want results from more Discord servers?
Add your server