none
Linq Language Help! RRS feed

  • Question

  • How would you write this in Linq-to-sql in VB.NET?

     

    Select Id and Number fields from Table1 Where Number is Like a variable and Table 3 has a related record.

     

    Table1 is linked to Table2 through a one-to-many relationship

    Table2 is linked to Table3 through a one-to-one relationship

     

    I have been trying to figure this out with these samples.

    http://msdn.microsoft.com/en-us/vbasic/bb688085.aspx

    Monday, September 22, 2008 7:35 PM

All replies

  • Hi

     

    I'm quite new to LINQ myself so I don't know if this solution is optimal or if there is a better solution out there (I'm sure there is). But this is what I use when I need to query across entitysets.

     

    Code Snippet

    var query = from t1 in DataContext.Table1

      where t1.Number == ID && t1.Table2s.Where(t2=>t2.Table3 != null).Any()

      select new

      {

    t1.Number,

    t1.Id

      };

     

    Regards

    Morgan

    Wednesday, September 24, 2008 6:44 AM