我有三个表一是" Allowance"," Balance"和" TimeoffRequests"在这三个表中的公共列是EmployeeId和TimeoffTypeId,现在我需要通过分组他们timeoffTypeId和EmployeeId表" TimeoffRequests"得到一个请假的一个请求时间,并得到" TimeOffHours" .因为我写的代码就像
var query = (from tr in TimeOffRequests
where tr.EmployeeID == 9
group tr by new { tr.EmployeeID, tr.TimeOffTypeID } into res
select new
{
EmployeeID = res.Key.EmployeeID,
TimeOffTypeID = res.Key.TimeOffTypeID,
TotalHours = res.Sum(x => x.TimeOffHours)
}).AsEnumerable();
Run Code Online (Sandbox Code Playgroud)

现在我需要将这些结果与第一个表联系起来,并且必须从所有员工中获取,并timeoffTypes从分组表中的UserAllowance相应TimeoffHours表中获取.为了得到左连接查询我写如下.
var requestResult = (from UA in UserAllowances
join UB in UserBalances on UA.EmployeeID equals UB.EmployeeID
where UA.TimeOffTypeID …Run Code Online (Sandbox Code Playgroud) 我正在研究MVC,在模型中我创建了一个使用Entity Framework的类.我试图从DBContext类继承,但它显示错误说:"类型或命名空间名称DBContext不存在".我还添加了"System.data.Entity"命名空间.
示例如:
public Class SampleEF :DBContext //Showing error
{
}
Run Code Online (Sandbox Code Playgroud)
你能告诉我如何使用DBContext类来使用EF吗?
我使用EDM查询作为IList类型从DataBase View Table获取值.
它给了一些元素集合.
从这个集合中,我想基于One Column过滤数据,但即使根据条件存在数据也不提供过滤数据查询如下所示.
对于从DataBase获取数据//它正在获取一些数据集合.
IList<EFModel.EntityModel.vwGetActiveEmployee> activeEmployeelist = TimeOffService.GetActiveEmployees();
Run Code Online (Sandbox Code Playgroud)
在这里,我想基于Column IsManger(值1或0)来存档数据.对于我写的那样
IList<EFModel.EntityModel.vwGetActiveEmployee> managerlist = activeEmployeelist.Where(p => p.IsManager == 1).Select(p => p) as IList<EFModel.EntityModel.vwGetActiveEmployee>;
Run Code Online (Sandbox Code Playgroud)
但这里的Managerlist显示空值.当我使用以下过滤数据
var emplistVar = activeEmployeelist.Where(p => p.IsManager.Equals(1)).Select(p => p);
Run Code Online (Sandbox Code Playgroud)
它显示了一些带有"var"类型的数据集合,但如果我给它类型它显示为null.这是什么原因,这个数据来自数据库视图数据.