Reputation: 2224
I am trying to return a list from my WCF service to the client.
I am using Entity Framework to query against my database
I have the following code in my Entity Framework library :
public List<Users> getUsersByLastName(string pLastName)
{
using (var context = new AMTEntitiesContainer())
{
var users = context.Users
.Where((c) => c.LastName.Contains(pLastName))
.ToList();
return users;
}
}
This is how I am capturing the result in my WCF and returning it :
public List<wcfUser> getUsersByLastName(string pLastName)
{
UserMethods userMethods = new UserMethods();
List<Users> usersList = userMethods.getUsersByLastName(pLastName);
List<wcfUser> usersListForClient = new List<wcfUser>();
wcfUser usersForClient = new wcfUser();
foreach (Users u in usersList)
{
usersForClient = new wcfUser();
TranslateServerUserToClientUser(u, usersForClient);
usersListForClient.Add(usersForClient);
}
return usersListForClient;
}
The thing is, for some reason the usersList is always empty..why so?
I checked that the DB is not empty by throwing the same queries into LINQPad
Upvotes: 0
Views: 2997
Reputation: 2224
This solved it, apparently the DB is returning something weird but this captured it :
private AMTEntitiesContainer context = new AMTEntitiesContainer();
public IEnumerable<Users> getUsersByLastName(string pLastName)
{
IQueryable<Users> results;
results = (from m in context.Users
where m.LastName.StartsWith(pLastName)
select m);
return results;
}
Upvotes: 1