✅ Is this how you are supposed to use .select() EF CORE

c#
// GET: api/Venture/5
[HttpGet("{id}")]
public async Task<ActionResult<VentureDto>> GetVenture(Guid? id)
{
// Attempt to find the Venture by its ID
return await _context.Ventures
.Where(v => v.Id == id)
.Select(v => new VentureDto
{
VentureId = v.Id,
VentureName = v.Name,
Portfolio = new PortfolioDto
{
Id = v.Portfolio.Id,
CoFounders = v.Portfolio.CoFounders,
CoFoundersFemale = v.Portfolio.CoFoundersFemale,
CompanyName = v.Portfolio.CompanyNam
// actually a lot more fields

Industry = new IndustryDto
{
Id = v.Portfolio.Industry.Id,
Name = v.Portfolio.Industry.Name
},
Tech1 = new Tech1Dto
{
Id = v.Portfolio.Tech1.Id,
Name = v.Portfolio.Tech1.Name
},
Tech2 = new Tech2Dto
{
Id = v.Portfolio.Tech2.Id,
Name = v.Portfolio.Tech2.Name
},
Sdgs = v.Portfolio.Sdgs.Select(s => new SdgDto
{
Id = s.Id,
Name = s.Name
}).ToList()
}
})
.FirstOrDefaultAsync();
}
c#
// GET: api/Venture/5
[HttpGet("{id}")]
public async Task<ActionResult<VentureDto>> GetVenture(Guid? id)
{
// Attempt to find the Venture by its ID
return await _context.Ventures
.Where(v => v.Id == id)
.Select(v => new VentureDto
{
VentureId = v.Id,
VentureName = v.Name,
Portfolio = new PortfolioDto
{
Id = v.Portfolio.Id,
CoFounders = v.Portfolio.CoFounders,
CoFoundersFemale = v.Portfolio.CoFoundersFemale,
CompanyName = v.Portfolio.CompanyNam
// actually a lot more fields

Industry = new IndustryDto
{
Id = v.Portfolio.Industry.Id,
Name = v.Portfolio.Industry.Name
},
Tech1 = new Tech1Dto
{
Id = v.Portfolio.Tech1.Id,
Name = v.Portfolio.Tech1.Name
},
Tech2 = new Tech2Dto
{
Id = v.Portfolio.Tech2.Id,
Name = v.Portfolio.Tech2.Name
},
Sdgs = v.Portfolio.Sdgs.Select(s => new SdgDto
{
Id = s.Id,
Name = s.Name
}).ToList()
}
})
.FirstOrDefaultAsync();
}
No description
6 Replies
Angius
Angius7mo ago
Yep
leowest
leowest7mo ago
No description
leowest
leowest7mo ago
this feels like it could be a list of Portfolio with an extra column enum Tech, Industry
Angius
Angius7mo ago
Apparently, Tech1 and Tech2 are more like "main" and "sub", something like Tech1: Javascript, Tech2: VueJS
leowest
leowest7mo ago
a bit confusing I guess, maybe rename Tech1 and 2 to MainTech, SubTech or something perhaps
restingphantom
restingphantomOP7mo ago
😅 yeah I know my internship location does it like this, unfortionately most of them dont have knowladge about software so this makes the most sense for them I guess
Want results from more Discord servers?
Add your server