小编Gim*_*ock的帖子

LINQ to Entities 无法识别该方法:LastOrDefault

概述:在 CompletedQuestions 表中,UserId 对应于完成该问题的用户。Id 属性对应于 Questions 表中的问题之一。我知道,我没有正确指定关系。但我不是很有经验。我只想完成一个项目,然后我会在了解更多信息后回来修复那些糟糕的编码实践。我无法理解以下异常。

LINQ to Entities does not recognize the method 'Riddle.Models.CompletedQuestion LastOrDefault[CompletedQuestion](System.Linq.IQueryable`1[Riddle.Models.CompletedQuestion])' method, and this method cannot be translated into a store expression.

    Line 46:                 if (RiddleCompleted == null)
    Line 47:                 {
    Line 48:                     var lastCompletedQuestion = _db.CompletedQuestions.Where(q => q.UserId == currentUserId) // exception occurs in this line
    Line 49:                                                                              .OrderBy(q => q.QuestionNumber)
    Line 50:                                                                              .LastOrDefault();
Run Code Online (Sandbox Code Playgroud)

发生异常的动作:

public ActionResult Riddle(int Id)
        {
            string currentUserId = User.Identity.GetUserId();
            var riddle = _db.Riddles.Where(r => r.Id == Id).Single();

            if …
Run Code Online (Sandbox Code Playgroud)

c# linq entity-framework-6 asp.net-mvc-5

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

为什么我们必须对 css 文件使用“link”标签

为什么不允许这样做:

<style src="someCssFile.css"></style>
Run Code Online (Sandbox Code Playgroud)

而这是允许的:

<script src="someJsFile.js"></script>
Run Code Online (Sandbox Code Playgroud)

我不明白为什么我必须对 css 文件使用链接标记。我认为使用样式标签更有意义。

html css

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

标签 统计

asp.net-mvc-5 ×1

c# ×1

css ×1

entity-framework-6 ×1

html ×1

linq ×1