gpt4 book ai didi

c# - EF6 异常 : DbExpressionBinding requires an input expression with a collection ResultType

转载 作者:行者123 更新时间:2023-11-30 14:22:33 26 4
gpt4 key购买 nike

我在运行此查询时遇到异常(使用 LinqPad 进行调试):

int[] serviceCodes= new int[] { 1610, 1611, 1612 };
byte[] payModes = new byte[] { 1, 2 };
int[] months = new int[] { 10, 11, 12 };
int year = 2017;

using (var context = new FinanceConnection())
{
var result = from a in
(from a in context.BILL_INFO_DETAILS
where
a.INPUT_STATUS == true &&
serviceCodes.Contains(a.SERVICE_INFO.SERVICE_CODE) &&
payModes.Contains(a.PAY_MODE_ID) &&
a.STAMP_DATE != null &&
months.Contains(a.STAMP_DATE.Value.Month) &&
a.STAMP_DATE.Value.Year == year &&
a.SERVICE_INFO.FEE > 1
select new
{
a.REQUESTED_QTY,
a.ITEM_TOTAL,
Dummy = "x"
})
group a by new { a.Dummy }
into g
select new ViewGuessAlMajlisOffline
{
Transaction =
g.Sum(p => p.REQUESTED_QTY) == 0 ? (int?)null : (int)g.Sum(p => p.REQUESTED_QTY),
Income = g.Sum(p => p.ITEM_TOTAL) == 0
? (decimal?)null
: (decimal)g.Sum(p => p.ITEM_TOTAL)
};

result.Dump();
}

我搜索了具有相同标题的 SO 问题,但我的包含列表是简单的数组,所以我不知道究竟是什么导致了异常。

非常感谢任何指点。

更新

我已经尝试删除其中的两个 .Contains() 并且查询有效。实际上,仅注释 payModes.Contains(a.PAY_MODE_ID) 使查询有效

更新

public partial class BILL_INFO_DETAIL : DA.Services.IBS.Data.EntityFramework.Helper.IBaseEntity
{
public string BILL_NO { get; set; }
public byte PAY_MODE_ID { get; set; }
public int CASHIER_NO { get; set; }
public int SERVICE_CODE { get; set; }
public Nullable<int> REQUESTED_QTY { get; set; }
public Nullable<int> CURRENT_QTY { get; set; }
public Nullable<decimal> FEE { get; set; }
public Nullable<decimal> ITEM_TOTAL { get; set; }
public Nullable<decimal> VAT_AMOUNT { get; set; }
public string USER_ID { get; set; }
public Nullable<int> BUSINESS_USER_ID { get; set; }
public Nullable<bool> INPUT_STATUS { get; set; }
public Nullable<System.DateTime> STAMP_DATE { get; set; }

public virtual BUSINESS_USER BUSINESS_USER { get; set; }
public virtual CASHIER CASHIER { get; set; }
public virtual PAY_MODE PAY_MODE { get; set; }
public virtual SERVICE_INFO SERVICE_INFO { get; set; }
}

最佳答案

当应用于 byte 数组时,Contains 方法转换似乎存在错误(在 EF6.1.3 和 6.2 中)(可能是因为通常使用字节数组来表示二进制数据)。

解决方法是使用 int 数组:

var payModes = new int[] { 1, 2 };

或显式可枚举(避免byte[]特殊处理):

var payModes = new byte[] { 1, 2 }.AsEnumerable();

请注意,向可枚举的转换应该在查询表达式树之外,因为 AsEnumerable() 调用无法被 EF 查询转换器识别并将生成 NotSupportedException

关于c# - EF6 异常 : DbExpressionBinding requires an input expression with a collection ResultType,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49123858/

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