Skip to content
Loading
  • Samir Bhogayta
    +1
    Thanks you very much 
    Veerendra Annigere
    +1
  • Suraj Kumar
    0
    You coluld try this
    1. List UserList = new List();  
    2.   
    3. UserList = (from p in dBModels.users    
    4. join f in dBModels.auth_assignment.Where(x => x.item_name == "Customer")    
    5. on p.id equals f.user_id    
    6. select new    
    7. {    
    8. id = p.id,    
    9. first_name = p.first_name,    
    10. last_name = p.last_name,    
    11. status = p.status    
    12. }).ToList();  
    13.   
    14. return View(UserList);   
     
    0
  • Veerendra Annigere
    0
    View expecting List of the User Model. But you're sending the generic Model. 
     
    1. public ActionResult Index()    
    2. {    
    3. var users = (from p in dBModels.users    
    4. join f in dBModels.auth_assignment.Where(x => x.item_name == "Customer")    
    5. on p.id equals f.user_id    
    6. select new User          <====== this  
    7. {    
    8. id = p.id,    
    9. first_name = p.first_name,    
    10. last_name = p.last_name,    
    11. status = p.status    
    12. }).ToList();    
    13. return View(users);    
    14. }    
     
    0
  • Samir Bhogayta
    0
    Hi..Veerendra
    I tried your code but getting this error.
     
    The entity or complex type 'ProjectnameModel.user' cannot be constructed in a LINQ to Entities query.'
    0
  • Samir Bhogayta
    0
    Hi..Suraj Kumar
    I tried your code but getting this error.
    The entity or complex type 'ProjectnameModel.user' cannot be constructed in a LINQ to Entities query.'
    0
  • Suraj Kumar
    0
    You have to change
    1. List UserList = new List();  
    2.   
    3. to  
    4.   
    5. List UserList = new List();  
    0
  • Samir Bhogayta
    0
    Hi..Suraj Kumar
     
    Please check this code. Still it gives an error
    1. List UserList = new List();  
    2. UserList = (from p in dBModels.users  
    3. join f in dBModels.auth_assignment.Where(x => x.item_name == "Customer")  
    4. on p.id equals f.user_id  
    5. select new  
    6. {  
    7. id = p.id,  
    8. first_name = p.first_name,  
    9. last_name = p.last_name,  
    10. status = p.status  
    11. }).ToList();  
    12. return View(UserList);  
    0
  • Veerendra Annigere
    0
    Check This 

    https://www.c-sharpcorner.com/blogs/error-the-entity-or-complex-type-cannot-be-constructed-in-a-linq-to-entities-query1
    0