小编thi*_*rzy的帖子

在 EF LINQ 查询 if 子句中抛出空引用异常

我找不到确切的词来解释正在发生的事情,所以如果这是一个重复的问题,我深表歉意。

我尝试在 LINQ 查询中执行一个非常简单的 AND 条件 if 子句,以检查对象是否为空,然后验证其属性是否等于我想要比较的列。

编码:

public IEnumerable<Plan> GetPlans(Plan plan)
    {
        return _context.Plans.Where(e =>
            e.Situation == plan.Situation &&
            e.Notes.Contains(plan.Notes) &&
            (plan.Excercise != null && plan.Exercise.Year > 0 ? e.Exercise.Year == plan.Exercise.Year: true)).ToList();
    }
Run Code Online (Sandbox Code Playgroud)

我之前在 .NET 4.5 中已经做过十几次这种检查,没有任何问题。

但是现在,在我正在处理的第一个 .NET Core 2.0 项目中,出现以下错误:

An exception was thrown while attempting to evaluate a LINQ query parameter expression. To show additional information call EnableSensitiveDataLogging() when overriding DbContext.OnConfiguring.
Run Code Online (Sandbox Code Playgroud)

内部异常更清晰:NULL REFERENCE EXCEPTION

经过一些测试,我发现错误发生在 plan.Exercise 为空时,即使我试图通过首先检查它是否为空来避免异常。

如果我尝试直接在立即窗口中进行相同的检查,它应该返回“false”。

我在这里错过了什么吗?这可能是一个EF错误?例如,为什么这在 .NET 4.5 中有效,而在 …

c# linq entity-framework asp.net-web-api .net-core

6
推荐指数
1
解决办法
1万
查看次数

如何在表格中显示好看的虚线边框?

为了为我的表格制作完美的间隔虚线,我已经在 CSS 上苦苦挣扎了几个小时。我尝试过 border 属性,创建一个图像并将其作为背景,在 Y 轴上重复它,以及其他一些东西(甚至在 CSS3 中),但我的情况比我通过搜索发现的情况更具体一些谷歌:我在表中交替了列和行类,似乎我无法用连续边框定义整行。

我的CSS:

th { height: 42px; font-weight: bold; font-size: 15px; vertical-align:bottom; padding: 8px 16px; margin-bottom: 5px; border-bottom: 2px dotted #999; }
th.odd { background-color: #e6e6e6; }
th.even { background-color: #ddd; }
td { padding: 16px; }
tr{ border-bottom: 2px dotted #999; }
tr.even { background-color: #eee; }
tr.even td.even { background-color: #e2e2e2; }
tr.odd td.even { background-color: #eaeaea; }
Run Code Online (Sandbox Code Playgroud)

正如我之前提到的,我还尝试将“边框底部”更改为带有点和空格的背景图像。

我今天所拥有的是这样的:

在此输入图像描述

我希望这些点是连续的,如下所示: 。。。。。。。。。。。。

html css

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

.net-core ×1

asp.net-web-api ×1

c# ×1

css ×1

entity-framework ×1

html ×1

linq ×1