Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
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 .

C#
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
C#
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 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
Posted
Updated 4-May-14 10:30am
v3
Comments
[no name] 4-May-14 11:48am    
"i get an error", probably because your code will not even compile.
"use of writing the classes and assigning the values to their properties", what would be the use of a single class that had the same data as every other class? What does security have to do with anything?
"why i am not be able to send a class from here", what does that even mean? You are returning "emp" what did you expect to return?
Torakami 4-May-14 12:25pm    
its a architecture , i am not interested in returning values direct from the database , all i want to do is in class properties first and then i want to return that class.

suggest me if you have the answer that can solve my answer .. it doesnt make sense that you should judge my pattern architecture which i am following ,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900