0

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

16
  • Would you check your translator? Commented Apr 18, 2013 at 17:31
  • I double checked my translator but still..the list is not null..is empty :( Commented Apr 18, 2013 at 17:38
  • What im getting on the client when invoking this function is d:[] Commented Apr 18, 2013 at 17:39
  • I pass the value of "m" or also ""..I even hard coded so that when it will do .Contains("") instead of receiving the parameter..but still it responds d:[] Commented Apr 18, 2013 at 17:50
  • @MaG3Stican So if you put a breakpoint on return usersListForClient; it is filled with data? If so, try updating your service reference. Commented Apr 18, 2013 at 17:51

1 Answer 1

1

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;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.