gpt4 book ai didi

java - asp MVC 存储库中的返回类型问题

转载 作者:行者123 更新时间:2023-12-01 17:37:00 28 4
gpt4 key购买 nike

我使用 list .Tolist() 但返回时显示错误。我在 asp.net MVC getaway/repository 中使用此方法。我也想找出这个问题但是没找出问题

public List<Floor> GetBuildingInfoByBuildId(int floor_Id)
{
var result = (from floor in db.Floors
join c in db.Campuses on floor.CampusID equals c.ID
join build in db.Buildings on floor.BuildingID equals build.ID
where (floor.ID == floor_Id)
select new
{
floor.ID,
floor.Floor_Name,
c.Campus_Name,
build.Building_Name
}).Tolist();
return result;
}

最佳答案

您需要在 select 语句中指定类对象。

public List<Floor> GetBuildingInfoByBuildId(int floor_Id)
{
return (from floor in db.Floors
join c in db.Campuses on floor.CampusID equals c.ID
join build in db.Buildings on floor.BuildingID equals build.ID
where (floor.ID == floor_Id)
select new Floor
{
floor.ID,
floor.Floor_Name,
c.Campus_Name,
build.Building_Name
}).Tolist();

}

希望对您有所帮助。

关于java - asp MVC 存储库中的返回类型问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61019942/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com