Microsoft LINQ Books

Programming Microsoft LINQ & Introducing Microsoft LINQ
Welcome to Microsoft LINQ Books Sign in | Join | Help
in Search

Simple LINQ join?

Last post 10-28-2007, 11.39 by edtijgen. 8 replies.
Sort Posts: Previous Next
  •  09-30-2007, 8.51 67

    Simple LINQ join?

    Hi All,
    Please consider the following database model


    Boy (table name)
    pk_BoyId (field)
    Name (field)

    BoyGirl (table name)
    fk_BoyId (field)
    fk_GirlId (field)

    Girl (table name)
    pk_Girl (field)
    Name (field)

    When using the ADO.NET Entity Framework model wizard on this database model the result is 2 entities

    Boy (Entity)
    pk_BoyId (Member)
    Name (Member)
    Girl (navigation property)

    Girl (Entity)
    pk_GirlId (Member)
    Name (Member)
    Boy (navigation property)


    Now How can I create a collection of girls to use in a join on Boy.
    So I'd like to get every Boy that has a relation to a girl from the collection of girls I created seperatly from the database.
    Something like this:

    List<Girl> girls = new List<Girl>();
    Girl girl = new Girl();
    girl.GirlId = 1;
    girl.Name = "Paula";
    girls.Add(girl);
    girl = new Girl();
    girl.GirlId = 3;
    girl.Name = "Debby";
    girls.Add(girl);

    var boys = from b in context.Boy
    join g in girls on b.girl == q

    select b;
    foreach (Boy resultBoy in boys)
    {
    Console.WriteLine(resultBoy.Name);
    }


    But this does not work, i am unsure how to proceed
  •  10-02-2007, 10.55 68 in reply to 67

    Re: Simple LINQ join?

    I don't have time now to do a complete repro - however, assuming you already have a correct EDM (Beta 2 editor sometimes requires some manual correction of generated XML), you want to mix a query to EDM and a query to an in-memory object. Probably you'd like to send a single SQL query to database, but to do that may be you need to create sume Girl entity without committing these changes.

    If you want to post a complete project (with EDM and C# source code) I would take a look during next week-end.

    Marco

  •  10-09-2007, 3.45 70 in reply to 68

    Re: Simple LINQ join?

    The Boy and Girl entity are both in the EDM. I want to join Boy.Girl on a Girl collection I create programatically. Please note that the collection of Girl objects consist of Girl objects from the EDM.
    Does this change anything to your understanding and perhaps would you be able to solve this?

    Also I am using the ado.net entity framework version that was released last month.

    If not I'll post my project once I get back home. That should be in about 2 weeks.

    Regards,

    Ed

  •  10-09-2007, 3.55 71 in reply to 70

    Re: Simple LINQ join?

    You should have the Beta 2.

    Yes, if you will send the project it would be the best - In these days I'm working on a different thing and this would simplify our analysis.

    Thank you,

     Marco

  •  10-26-2007, 10.19 76 in reply to 71

    Re: Simple LINQ join?

    Ok I am back from my trip and I am now using a different account that I can use from work. Can you please tell me how I can get my BoyGirl solution to you? It is really small and included a console app and a db project so it should be real easy for you to set up.

    thanks in advance,

    Ed

  •  10-26-2007, 10.30 78 in reply to 71

    Re: Simple LINQ join?

    By the way I have .NET framework 3.5 beta 2
  •  10-26-2007, 6.48 79 in reply to 76

    Re: Simple LINQ join?

    You can send it to

    marco (at) devleap (dot) com

    Marco

  •  10-27-2007, 10.33 80 in reply to 79

    Re: Simple LINQ join?

    I zipped my solution and emailed it to you, but it got bounced stating that I had an illigal attachment. So how can I get my solution to you without zipping it? rar maybe? but I suspect the same kind of security measures

    Ed

  •  10-28-2007, 11.39 81 in reply to 80

    Re: Simple LINQ join?

    Ok I rarred it now and it does not seem to bounce this time. So you should have my solution in your inbox now.

    Thanks for taking the time to help me out. I will share the solution with everyone ofcourse after one is found.

View as RSS news feed in XML
Powered by Community Server (Personal Edition), by Telligent Systems