none
Do not get the && to work with LINQ RRS feed

  • Question

  • This it what im trying to do, but for some reason the (&& u.status == 0) does not seem to work

    public List<View_EAK_BookingStatus> SearchBookings(int uthyrningsId)
    {
    var querySearchBookings = from u in globalDBConnString.context.View_EAK_BookingStatus
    where u.uthyrningsId == uthyrningsId && u.status == 0
    select u;
    return querySearchBookings.ToList();
    } 


    This works for me, i get the wrong result, but it works.

    public List<View_EAK_BookingStatus> SearchBookings(int uthyrningsId)
    {
    var querySearchBookings = from u in globalDBConnString.context.View_EAK_BookingStatus
    where u.uthyrningsId == uthyrningsId
    select u;
    return querySearchBookings.ToList();
    } 

    If i do it in SQL it works just fine.

    SELECT * 
    FROM View_EAK_BookingStatus 
    WHERE uthyrningsId = 3 AND status = 0;

    So whats wrong with my first Linq query? how do i get (&& u.status == 0) to work?


    Systemdeveloper @ 4film

    Thursday, October 16, 2014 10:02 AM

Answers

  • Hello Edvard,

    >>So whats wrong with my first Linq query? how do i get (&& u.status == 0) to work?

    The query syntax should be ok since I made a similar query with yours and it worked as expected:

    var result = (from o in db.Orders
    
                                  where o.OrderID == 1 &&o.OrderName == "1"
    
                                  select o).ToList();
    

    >>This it what im trying to do, but for some reason the (&& u.status == 0) does not seem to work

    Please describe how it does not work for you, does it throw any exception? If it has, please share it with us. And since you are using LINQ2SQL, please try to use the below code to check the real executed sql statement:

    db.Log = Console.Out;

    If the generated sql statement is ok. Then I suggest that you should check the data in database.

    Best Regards,

    Fred.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, October 17, 2014 3:52 AM
    Moderator