none
LINQ where ?? RRS feed

  • Question

  • I have a problem with the query, this query lists all the reservations but I want only the current logged 
    in user. I do not know what to put where such request ?
     public static List<Reservations> get(Client loggedClient)
            {
                var res = (from A in request.Reservations
                            select A).ToList();
                return res;
            }
    var res = (from A in request.Reservations
               where = ??
               select A).ToList();
               return res;
    Friday, August 5, 2011 10:27 AM

Answers

  • I solved the problem :
    var res = (from A in request.Reservations
    where A.Client.ClientID == loggedClient.ClientID 
    select A).ToList();
    return res;
    • Marked as answer by ClientID Friday, August 5, 2011 1:05 PM
    Friday, August 5, 2011 10:38 AM
  • Hi,

    Since you didn't supply any details about the model the following code is a guess tha might answer your question:

    var res = (from reservation in request.Reservations
                    where reservation.Client.UserName == loggedClient.Username
                    select reservation).ToList();
    return res;

    The query I wrote is based on the assumption that there is a relation between reservations and clients.
    Please supply details about your model if that doesn't help you to figure out how to write the query.


    Gil Fink
    • Marked as answer by ClientID Friday, August 5, 2011 1:05 PM
    Friday, August 5, 2011 10:38 AM

All replies

  • I solved the problem :
    var res = (from A in request.Reservations
    where A.Client.ClientID == loggedClient.ClientID 
    select A).ToList();
    return res;
    • Marked as answer by ClientID Friday, August 5, 2011 1:05 PM
    Friday, August 5, 2011 10:38 AM
  • Hi,

    Since you didn't supply any details about the model the following code is a guess tha might answer your question:

    var res = (from reservation in request.Reservations
                    where reservation.Client.UserName == loggedClient.Username
                    select reservation).ToList();
    return res;

    The query I wrote is based on the assumption that there is a relation between reservations and clients.
    Please supply details about your model if that doesn't help you to figure out how to write the query.


    Gil Fink
    • Marked as answer by ClientID Friday, August 5, 2011 1:05 PM
    Friday, August 5, 2011 10:38 AM