为什么我们不能创建类的新实例并将其作为结果发送到实体框架中? [英] Why we cannot create new instance of the class and send it as a result in entity framework ?
问题描述
大家好,
我正在尝试的是,我在课堂库中有我的模型文件夹。
,因为我创建了一个Employee类,并在我的控制器中调用方法重新启动..
我的问题是。
Hi All ,
What i am trying is that , i have my model folder inside class library.
in that i have created a Employee class and calling the method retrurn inside this frommy controller ..
My question is that .
public Employee GetEmployeeDetailsById(int Id)
{
EmployeeContext _db = new EmployeeContext();
//var emp = (from em in _db.Employees.Where(e => e.EmployeeId == Id)
// select new Employee {
// EmployeeId=em.EmployeeId,
// FirstName=em.FirstName,
// LastName=em.LastName,
// Title=em.Title
// }).SingleOrDefault();
return emp;
}
当我尝试这样返回时出现错误..
但是如果我喜欢以下
when i try to return like this i get an error ..
however if i do like below
public Employee GetEmployeeDetailsById(int Id)
{
EmployeeContext _db = new EmployeeContext();
var emp = (from em in _db.Employees.Where(e => e.EmployeeId == Id) select em).SingleOrDefault();
return emp;
}
i dodnt得到任何错误..
为什么我无法发送这是一个类。
编写类并将值分配给它们的属性以获得更高的安全性有什么用?我无法做到这一点
i dodnt get any error ..
why i am not be able to send a class from here .
what is the use of writing the classes and assigning the values to their properties for more security then ? i am not able to do this then
推荐答案
这篇关于为什么我们不能创建类的新实例并将其作为结果发送到实体框架中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!