none
three tables with linq

    Question

  • How do I create a query that, passing a variable "var_lot", tell me in which pieces
    is such a "var_lot"? I have a table "Warehouse" with purchases of the various components.
    then I have a table "Pieces" with the pieces that I produce and
    a table "DetailsPiece" with a list of the components used.
    I tried this but it should not be:

        from w in data.Warehouse
                                    join dp in data.DetailsPiece on w.idwarehouse equals dp.idwarehouse
                                    join p in data.Pieces on dp.idpiece equals p.idpiece
                                    where w.Lot_production.Equals(var_lot)
                                    select new my_object
                                    {..}


    the tables are like this:
        Warehouse: idwarehouse, description, lot_production
        DetailsPiece:iddetail, idwarehouse, idpiece
        Pieces: idpiec, edescription



    thanks for any help

    Tuesday, June 04, 2013 7:29 AM

Answers

  • Hi duppino;

    According to your class layout the query should like the following.

    var results = from w in data.Warehouse
                  join dp in data.DetailsPiece on w.ID equals dp.IDWAREHOUSE 
                  join p in data.Pieces on dp.IDPIECE equals p.ID
                  where w.Lot_production.Equals(var_lot)
                  select new my_object
                  {..}

    If the above query does not work out for you please take a screen shot of the dbml designer of the classes from the query and post here.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by duppino Wednesday, June 12, 2013 7:59 PM
    Tuesday, June 11, 2013 4:24 AM

All replies

  • But that Linq you showed doesn't work? What's the error?
    Wednesday, June 05, 2013 10:42 AM
  • What is wrong with this?

    from w in data.Warehouse
                                    join dp in data.DetailsPiece on w.idwarehouse equals dp.idwarehouse
                                    join p in data.Pieces on dp.idpiece equals p.idpiece
                                    where w.Lot_production = var_lot
                                    select new my_object
                                    {..}


    Please Mark as Answer and Vote as Helpful if I helped.

    Also please visit my blog http://msguy.net/

    Wednesday, June 05, 2013 1:09 PM
  • For example:
    Pieces table contains:
    ID   NAME
    1     bicycle
    2     table
    3     computer



    Warehouse table contains:
    ID     MATERIAL
    1      iron
    2      plastic
    3     screws
    4     wire
    5     glue
    6    wood
    7    tape
    8    rubber



    DetailsPiece table contains:
    IDPIECE     IDWAREHOUSE
    1                    1
    1                    2
    1                    3
    1                    8
    (iea bicycle comprising: iron, plastic, screws and rubber)

    2 5
    2 6
    (ie, a table consisting of: glue and wood)

    3 1
    3 2
    3 3
    (ie, a computer consisting of:iron, plastic and screws)



    If I want to know the parts where there are screws, the query I should say
    bycicle
    computer

    As for the glue would say only
    table


    In these queries I have some doubts I'm not sure that the joins are always correct:
    from w in data.Warehouse
                                    join dp in data.DetailsPiece on w.idwarehouse equals dp.idwarehouse
                                    join p in data.Pieces on dp.idpiece equals p.idpiece
                                    where w.Lot_production.Equals(var_lot)
                                    select new my_object
                                    {..}

    thanks

    greetings


    • Edited by duppino Wednesday, June 05, 2013 8:55 PM
    Wednesday, June 05, 2013 8:53 PM
  • Hi duppino;

    According to your class layout the query should like the following.

    var results = from w in data.Warehouse
                  join dp in data.DetailsPiece on w.ID equals dp.IDWAREHOUSE 
                  join p in data.Pieces on dp.IDPIECE equals p.ID
                  where w.Lot_production.Equals(var_lot)
                  select new my_object
                  {..}

    If the above query does not work out for you please take a screen shot of the dbml designer of the classes from the query and post here.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by duppino Wednesday, June 12, 2013 7:59 PM
    Tuesday, June 11, 2013 4:24 AM
  • Hi Fernando,

    my fear is that I thought I follow the wrong method, but since it has confirmed to me I feel more comfortable.
    Having a lot of data I can not see if output is correct, that's all.

    thank you very much

    p.s. the id is reversed only my writing error ;)


    • Edited by duppino Wednesday, June 12, 2013 8:03 PM
    Wednesday, June 12, 2013 7:59 PM
  •   

    Not a problem duppino, glad to be of help.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, June 13, 2013 1:12 AM