Cannot implicitly convert type 'System.Collections.Gener

本文关键字:System Collections Gener implicitly convert type Cannot | 更新日期: 2023-09-27 17:50:45

我已经在尝试获得与EntityFramework LINQ查询的JOIN的第一次尝试。当我创建这个没有连接的查询时,我不会得到错误。我需要做什么?

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;
}

Cannot implicitly convert type 'System.Collections.Gener

您正在选择一个新的匿名类型。相反,选择new PLANT对象

select new PLANT
 {
    //set values here
 }).ToList();

edit*只是注意到你想从flowers中引入一个值——在这种情况下,你可以为bloom desc创建一个新的非映射属性到PLANT类,或者你可以创建一个包含bloom和PLANT属性的新类,然后选择它

相关文章: