本文介绍了只有原始类型或枚举类型在这种情况下,支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过很多关于这一主题的问题,但我一直无法通过任何人进行排序,实际上解决了我看到的问题。我有一个跟踪哪个员工被分配到还有哪个员工创造的记录和更新它的活动的实体。如果删除了`那里a.AssignedEmployee ==的currentUsercode行,我没有得到以下运行时错误。

CONTROLLER

var query = from a in db.Activities
            where a.AssignedEmployee == currentUser
            where a.IsComplete == false
            orderby a.DueDate
            select a;
return View(query.ToList());

VIEW

@model IEnumerable<Data.DataModels.Activity>
..........
解决方案

My guess is that error indicates that EF cannot translate the equality operator for Employee to SQL (regardless of whether you're assuming referential equality or an overridden == operator). Assuming the Employee class has a unique identifier try:

var query = from a in db.Activities
            where a.AssignedEmployeeId == currentUser.Id
            where a.IsComplete == false
            orderby a.DueDate
            select a;
return View(query.ToList());

这篇关于只有原始类型或枚举类型在这种情况下,支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 15:46