gpt4 book ai didi

c# - 与 System.Linq.IQueryable 结合得到错误

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

我正在尝试按如下方式使用联合:

var query1 = from c in dc.Hotel_Meals_TBLs
where c.CHDLunch != "0" && c.CHDLunch != ""
select new
{
SERVICE_CODE = c.HotelCodeID,
SERVICE_NAME = c.HotelName,
ROOM_CATEGORY = "",
ROOM_TYPE = "",
VARIANCE_NAME = "CHILDLUNCH",
MARKET = "WW",
CONTRACT_BUSINESS_YEAR = "2014/2015",
CONTRACT_START_DATE = "01/11/2014",
CONTRACT_END_DATE = "30/10/2015",
TYPE = "CHILD POLICY",
CURRENCY = c.CurrencyCode,
PERIOD_NAME = "",
PERIOD_START_DATE = "",
PERIOD_END_DATE = "",
PRICE = c.Lunch,
PERCENTAGE = c.CHDLunch + "%",
NUM_TO_STAY = "",
NUM_TO_PAY = "",
PENALTY_TIME_LIMIT = "",
PENALTY_NO_DAY_BEFORE = "",
CHILD_REFERENCE = "",
TEXT = c.ChildPolicy
};
var query2 = from c in dc.Hotel_Meals_TBLs
from d in dc.HotelPeriod_TBLs
from f in dc.HotelRoom_TBLs
where c.HotelCodeID == d.HotelCodeID && c.HotelCodeID == f.HotelCodeID && f.DBL_HighSeason != 0 && d.PeriodName == "High"
select new
{
SERVICE_CODE = c.HotelCodeID,
SERVICE_NAME = c.HotelName,
ROOM_CATEGORY = f.RoomName,
ROOM_TYPE = "DBL",
VARIANCE_NAME = "",
MARKET = "WW",
CONTRACT_BUSINESS_YEAR = "2014/2015",
CONTRACT_START_DATE = "01/11/2014",
CONTRACT_END_DATE = "30/10/2015",
TYPE = "COST",
CURRENCY = c.CurrencyCode,
PERIOD_NAME = d.PeriodName,
PERIOD_START_DATE = d._From,
PERIOD_END_DATE = d._To,
PRICE = f.SGL_LowSeason,
PERCENTAGE = "",
NUM_TO_STAY = "",
NUM_TO_PAY = "",
PENALTY_TIME_LIMIT = "",
PENALTY_NO_DAY_BEFORE = "",
CHILD_REFERENCE = "",
TEXT = ""
};
var result = query1.Union(query2);

我得到了这个错误:

'System.Linq.IQueryable<AnonymousType#1>' does not contain a definition for 'Union' and the best extension method overload 'System.Linq.ParallelEnumerable.Union<TSource>(System.Linq.ParallelQuery<TSource>, System.Collections.Generic.IEnumerable<TSource>)' has some invalid arguments

Instance argument: cannot convert from 'System.Linq.IQueryable<AnonymousType#1>' to 'System.Linq.ParallelQuery<AnonymousType#2>'

真的,我多次使用这个方法,没有出现错误......你知道这个查询有什么问题吗?

最佳答案

错误消息表明 .NET 认为这两种匿名类型不同。为了使两个匿名类型相同,它们必须具有相同数量的具有相同名称和类型的属性。我查看了您的属性(property) list ,它们似乎以相同的顺序具有相同的名称。但是,您可能在这些方面有不同的类型:

类型 1

PERIOD_START_DATE = ""
PERIOD_END_DATE = ""
PRICE = c.Lunch,
TEXT = c.ChildPolicy

类型 2

PERIOD_START_DATE = d._From
PERIOD_END_DATE = d._To
PRICE = f.SGL_LowSeason
TEXT = ""

确保 d._Fromd._Toc.ChildPolicy 都是字符串并且 c.Lunch f.SGL_LowSeason 是同一类型(例如,可能一个是 int,另一个是 decimal)。

关于c# - 与 System.Linq.IQueryable 结合得到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30115995/

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