c# – EF6异常:DbExpressionBinding需要一个带有ResultType集合
发布时间:2020-12-16 01:26:06 所属栏目:百科 来源:网络整理
导读:我运行此查询时遇到异常(使用 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 r
我运行此查询时遇到异常(使用
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; } } 解决方法
当应用于字节数组时,似乎存在包含方法转换的错误(在EF6.1.3和6.2中)(可能是因为字节数组通常用于表示二进制数据).
解决方法是使用int数组: var payModes = new int[] { 1,2 }; 或显式枚举(以避免byte []特殊处理): var payModes = new byte[] { 1,2 }.AsEnumerable(); 请注意,转换为enumerable应该在查询表达式树之外,因为EF查询转换器无法识别AsEnumerable()调用,并且会生成NotSupportedException. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |