I have a table called "Cowork" and another called "Commune". In a controller I receive a parameter called NameCommune, given that value I need to find the ID that matches the received parameter, the result of the above I need to evaluate if that ID exists in the "COWORK" table. (THE TWO TABLES ARE RELATED) I'm new to using LINQ, any ideas for this? I have tried the following, but it returns an empty [ ]
public IActionResult GetNearbyPlaces(string nameComuna)
{
IQueryable<Commune> queryCommune = _context.Commune;
IQueryable<Cowork> queryCowork = _context.Cowork;
var codeCommune = (from code in queryCommune where code.name == nameComuna select code.code);
var coworkList = (from c in _context.Cowork where c.commune_code == codeCommune.ToString() select c).ToList();
return Ok(coworkList); // This returns an empty [ ]
}
In my common table the ID or my primary key is represented by the name code.
codeCommune.ToString()returnsSystem.Collections.Generic.List``1[Commune].Where(code => (code.name == value(<>c__DisplayClass5_0).nameComuna)).Select(code => code.code)?