I have worked on trying to get this first attempt at a JOIN with the EntityFramework LINQ query. When I create this query without the join, I don't get the error. What do I need to do?
public List<PLANT> getPlantDetails(int plantid)
{
List<PLANT> plantDetails = (from plant in db.PLANTs
join bloom in db.BLOOMs on plant.PLANT_ID equals bloom.PLANT_ID
where plant.PLANT_ID == bloom.PLANT_ID
&& plant.PLANT_ID == plantid
select new
{
plant.PLANT_ID,
plant.PL_GENUS,
plant.PL_SPECIES,
plant.PL_NAME,
plant.PL_DESC,
plant.PL_HEIGHT,
plant.PL_SPACING,
plant.PL_IMAGE,
plant.PL_IMAGE_THUMB,
bloom.BLOOM_DESC
}).ToList();
return plantDetails;
}
答案 0 :(得分:2)
you are selecting a new anonymous type. Instead, select new PLANT object
select new PLANT
{
//set values here
}).ToList();
edit* just noticing you want to bring in a value from BLOOMs - in that case you can maybe create a new non-mapped property to the PLANT class for bloom desc or you can create a new class which holds BLOOM and PLANT properties and then select that instead.