zoukankan      html  css  js  c++  java
  • 最近使用LINQ遇到的故障

     

    1.成员“YouXieKu.Models.Product.Published”不支持转换为 SQL

        public partial class Product{
                .......

            public bool Published
            {
                get
                {
                    return (this.ReleaseDate <= DateTime.Now && (this.ExpireDate > DateTime.Now||this.ExpireDate==null)&&this.Storage.Count>0&&this.Approved==true);

                }
            }

    }
    可能原因:在执行LINQ查询时不该使用分部类中新增的属性值Published,直接通过原始值this.ReleaseDate <= DateTime.Now && (this.ExpireDate > DateTime.Now||this.ExpireDate==null)&&this.Storage.Count>0&&this.Approved==true去判断

    提示:由于以前的函数求值超时,函数求值被禁用。必须继续执行才能重新启用函数求值

    可能原因:这是因为调试时会自动对Local/Watch等窗口里面(或鼠标停留所在)的变量求值,为了防止用户写的程序错误(比如死循环),系统有一个超时限制, 如果某个属性的get中做了很复杂的操作(而不是简单地返回一个私有变量的话),就有可能超过这个时间限制(如果strPage很大的话,你的正则运算就 很可能会超时)。
    可以禁用自动求值的功能:
    工具 -> 选项 -> 调试 -> 常规 -> 启用属性求值和其他隐式函数调用
    去掉前面打勾,不过这样就不会对属性变量自动求值了。

    3.LINQ语句  运行的时候提示"不支持带有本地集合的查询"

    List<Department> _departments = dataContext.Department.GetAllChildDepartments(department);

                var _ProductUnderDepartment =
                    (from a in dataContext.Product
                     let departmentIds = from b in _departments
                                         select b.DepartmentID
                     where departmentIds.Contains(a.ProductID) == true && a.ReleaseDate <= DateTime.Now && (a.ExpireDate > DateTime.Now || a.ExpireDate == null) && a.Storage.Count > 0 && a.Approved == true
                     select a).ToList();

    不使用let departmentIds = from b in _departments   select b.DepartmentID 来动态从本地集合 _department 获取一组查询

    改用直接先从_departments获取一组查询 List<int> _departments = dataContext.Department.GetAllChildDepartments(department).Select(p=>p.DepartmentID).ToList();

                var ProductUnderDepartment =
                    (from a in dataContext.Product
                     where _departments.Contains(a.ProductID) == true && a.ReleaseDate <= DateTime.Now && (a.ExpireDate > DateTime.Now || a.ExpireDate == null) && a.Storage.Count > 0 && a.Approved == true
                     select a).ToList();
                var _ProductUnderDepartment = (from b in ProductUnderDepartment
                                               let s = from c in b.Storage
                                                       select c.UnitsInStock
                                               where s != null && s.Sum() > 0
                                               select b).ToList();
                return _ProductUnderDepartment;

  • 相关阅读:
    C#中怎样将数组的顺序打乱随机排序
    C#中怎样获取System.Drawing.Color的所有颜色对象并存到数组中
    ZedGraph怎样实现将图形右键菜单的打印和页面设置合并为打印的二级子菜单
    C#中怎样在ToolStripMenuItem下再添加子级菜单
    Dubbo搭建HelloWorld-搭建服务提供者与服务消费者并完成远程调用(附代码下载)
    AndroidStudio下载安装教程(图文教程)
    Dubbo环境搭建-管理控制台dubbo-admin实现服务监控
    前端冷知识集锦
    console.log()显示图片以及为文字加样式
    vue数据请求显示loading图
  • 原文地址:https://www.cnblogs.com/lushuicongsheng/p/2025269.html
Copyright © 2011-2022 走看看