I have 2 API endpoints which have similarities so I am trying to reuse some similar code. I have an EF Core method syntax to retrieve data and this query is used in both.
Rather than repeat it in both, as the Select()
s are identical, I am trying to put it into a method.
This is one of the queries
var exhibitors = await Db.CompanyDescriptions
.Join(Db.Companies, cd => cd.CompanyId, c => c.CompanyID, (cd, c) => new { cd, c })
.Where(q => uniques.Any(id => id == q.cd.CompanyId)).Where(q => q.cd.EventId == eventId)
.Select(s => new ExhibitorModel()
{
Id = s.cd.Id,
EventId = s.cd.EventId,
}).ToListAsync();
Snipped for brevity, but I have this same code in another method (mostly) and then the methods go separate ways in terms of the unit of work, so I am trying to do something like this:
private ExhibitorModel MarshallExhibitorModel(CompanyDescriptions cd, Company c)
{
return new ExhibitorModel()
{
Id = cd.Id,
EventId = cd.EventId,
};
}
And then be able to use that in both Select()
s, but I am unsure of how to form that syntax.
In this line
.Select(s => new ExhibitorModel()
How can I say call MarshallExhibitorModel and pass in s.companydescription
and s.company
?