gpt4 book ai didi

c# mvc apicontroller 五表连接和返回值

转载 作者:太空宇宙 更新时间:2023-11-03 13:07:04 25 4
gpt4 key购买 nike

谁能告诉我,我已经加入了五个表并且我已经测试过加入是正确的。当我调试到“Location1”值时返回。

我还添加了 return Location1,它说

"Error 1 Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.IEnumerable'. An explicit conversion exists (are you missing a cast?)"

我的问题是如何显示回流阀?

这是我的 ApiController 和类代码。

 public class Posts
{

public Suburb suburb { get; set; }
public SubRegion subRegion { get; set; }
public SubRegionDeliveryTime subRegionDeliveryTime { get; set; }
public DeliveryTime deliveryTime { get; set; }
public DeliveryPeriod deliveryPeriod { get; set; }

}



public IEnumerable<Posts> Get()

{

using (ApplicationDbContext db = new ApplicationDbContext())
{

var Location1 = (from su in db.TLCSuburb
join Subr in db.TLCSubRegion on
su.SubRegionID equals Subr.SubregionID
join srdt in db.TLCSubRegionDeliveryTime on
Subr.SubregionID equals srdt.SubregionID
join DT in db.TLCDeliveryTime on
srdt.DeliveryTimeId equals DT.DeliveryTimeId
join DP in db.TLCDeliveryPeriod on
DT.DeliveryPeriodID equals DP.DeliveryPeriodID
orderby Subr.SubregionID
select new
{
su.name,
su.postcode,
su.AuState,
su.Latitude,
su.Longitude,
DT.DeliveryDay,
DP.PeriodType,
Subr.CloseDayId,
Subr.SubregionName,
}).ToList();


//return null;


return Location1;



}


}

最佳答案

这样写:

var  Location1 = (from su in db.TLCSuburb
join Subr in db.TLCSubRegion on
su.SubRegionID equals Subr.SubregionID
join srdt in db.TLCSubRegionDeliveryTime on
Subr.SubregionID equals srdt.SubregionID
join DT in db.TLCDeliveryTime on
srdt.DeliveryTimeId equals DT.DeliveryTimeId
join DP in db.TLCDeliveryPeriod on
DT.DeliveryPeriodID equals DP.DeliveryPeriodID
orderby Subr.SubregionID
select new Post
{
suburb = new Suburb(){
Name = su.name,
PostCode = su.postcode,
AuState = su.AuState,
Latitude = su.Latitude,
Longitude = su.Longitude
},
deliveryTime = DT.DeliveryDay,
deliveryPeriod = new DeliveryPeriod(){
PeriodType = DP.PeriodType
},
subRegion = new SubRegion(){
CloseDayId = Subr.CloseDayId,
SubRegionName = Subr.SubregionName
}
}).ToList();

您必须将其显式转换为 IEnumerable<Post>而不是匿名类型。

关于c# mvc apicontroller 五表连接和返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30420096/

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