locked
help me with a EF query RRS feed

  • Question

  • Hello !

    I'm trying to create a entity framework query for this situation :

    Table1                           Table2                              Table3

    --------------------------------------------------------------------------

    ID1                                 ID2                                  ID3  

    Name                             group                               status

    Age                               social                                 ID1

                                          ID1

     

    Table 1 has relation 1:1 with Table 2  ( on ID1 )

    Table1  has relation  1:To many  with table 3 (on ID1)

    I want to create a query ( Entity framework) to select :

    All the records on Table1 where  related record on table2 has group=5  and  the last record related on table 3 ( order by ID3) has status=true ( for example if on table 3 there are 2 records related , should check the last of them if status=true)

    I Try this code : ------------------------------------------------

    Dim  query =  From  t  In  context.Table1  

                Where  t.Table2.Any(Function (t1) t1.group=5) And

                t.table3.Last(Function(t2) t2.status=true )

                Select t

     

    -------------------------------------------------

     

    but , doesn't work . What can i do ?

    Thank you.

     

    • Edited by dcode25 Tuesday, November 8, 2011 1:57 AM
    Tuesday, November 8, 2011 1:49 AM

Answers

  • Hi dcode25,

    I think the problem relates to Last() method.

    To tell you truth, I'm not good at VB.net:

     var query = from t in context.Table1
                               where  t.Table2.Any(t2=>t2.group==5)                            select e;
                    var t = from q in query.ToList() where q.Table3.Last().States== true select q;
    


     Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Alan_chen Wednesday, November 16, 2011 2:19 AM
    Wednesday, November 9, 2011 7:38 AM