How do I create a Linq query with a many to many relationship model RRS feed

  • Question

  • Hi

    I have a many to many relationship with the linking table that holds specific information to the many to  many relationship as such

    DB a {a_ID, ...}

    DB b {b_ID,...}

    DB c {c_ID,a_ID,b_ID, cdate,....}

    I want to create a Linq statment(s) that takes each unique a<=>b relationship and finds the a<=>b with the newest date. I figure Max will get the latest date but I can't figure out the how LINQ can work the grouping.

    I also hope what  I am saying makes sense



    Tuesday, September 13, 2011 2:55 AM

All replies

  • easiest is always to begin with the table that holds the foreign key.


    var query = from row in context.C
                       select row;
    return query.Distinct();


    Tuesday, September 13, 2011 9:12 AM
  • I dont very understand your means. what's the meaning of newest date in your question?



    Just a newbie for everything.
    Wednesday, September 14, 2011 6:16 AM
  • Any update? Would you mind letting us know how it goes now?

    Please feel free to let us know if you need furhter support.


    Larcolais Gong[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.

    Tuesday, September 20, 2011 2:07 AM
  • I couldn't get it to work so I restructured my database tables splitting off  the inventory history aspect solving my problem
    Tuesday, September 20, 2011 11:38 PM