Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using N-tier and Entity Framework for my project. I have been using Database First.

I have a problem with may project, I can't return List<>. below is my code :

C#
public List<BuyerMaster> GetDetailBuyerMaster(string idCust)
   {
       var query = _context.sp_BuyerMaster_GetDetailById(idCust);
       return query;
   }


Thanks all !
Posted
Comments
Pheonyx 16-May-13 6:11am    
can you do query.ToList() ?
khiemnguyen 16-May-13 6:29am    
I try query.ToList() but it still error => " cannot implicitly convert type List to List " :(

When using store procedure in entity framework it returns
ObjectResult<ttype>
so you need to cast it your required type.
You can cast using Select operator as below
C#
return query.Select(x=> new BuyerMaster{
// Assign properties here 
Id = x.Id
}).ToList()
 
Share this answer
 
v3
Have a read here, there are a couple of approaches that might do what you are after:

http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/16e1aa09-3df7-40fa-baaf-b9bcc8c25d17[^]
 
Share this answer
 
Thanks all. My code runs Okay !
 
Share this answer
 

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