locked
help me with LINQ statement to give IN clause in where condition RRS feed

  • Question

  • I have  the following model

    DepotModel
    DepotNo int
    Depotname string

    DepotBreakLock DepotNo int [Column("isLocked")] public bool isBreakLocked { get; set; }
    [Not Mapped]
    DepotName string UserDepotLink UserId int DepotNo int

    I want to get the  same sql given below  in LINQ  please help . The result  should be getting into the  Var 'Datalist'

    var Datalist= 
    select A.DepotNo,A.DepotName,b.isLocked, CASE WHEN B.isLocked = 1 THEN 'Closed' ELSE 'Open' END AS Status from Depot A left join BreakLogLock] B on A.DepotNo=B.DepotNo where A.DepotNo in (select DepotNo from UserDepotLink where userid = 3)


    polachan

    Thursday, November 21, 2019 3:41 PM

All replies

  • In which way is this related to SQL Server, the topic of this forum? Better post to a .NET/Linq related forum.

    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Thursday, November 21, 2019 5:20 PM
  • Hi polachan,

    I noticed that you have more than one "select" in the sql. In Linq, I recommend separating them. About how to "select" by Linq, you can follow this.

    var queryResults =
        from n in names
        where n = "name"
        select n;

    As to the "left join", you can try keyword "join" in Linq.

     var query = from person in people
                 join pet in pets on person equals pet.Owner into gj
                 from subpet in gj.DefaultIfEmpty()
                 select new { person.FirstName, PetName = subpet.Name };

    Hope these can help you.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 22, 2019 5:09 AM