none
LINQ outer join doesn't seem to work (C#) RRS feed

  • Question

  • I'm trying to find prices that are not on the webserver and add them from the Dynamics GP Server. But when I run this code, it appears to be trying to add records that are already in the web server database.

     Here is my code:

                 MySQLWholesaleEntities db2 = new MySQLWholesaleEntities();  //Web Server Prices
                db2.CommandTimeout = 600;
                web_galaxyEntities db1 = new web_galaxyEntities();  //GP Prices
                db1.CommandTimeout = 600;
                Console.WriteLine("Filling wholesale price table");
                var mysqlPrices = new List<webWholeSaleInventoryPrice>(db2.webWholeSaleInventoryPrices);
                Console.WriteLine("web prices count = " + mysqlPrices.Count().ToString());
                Console.WriteLine("filling GP price tables");
                var GpPrices = new List<gvaWholeSaleInventoryPrice>(db1.gvaWholeSaleInventoryPrices);
                Console.WriteLine("GP prices count = " + GpPrices.Count().ToString());
                //add prices
                var addquery = from gp_price in GpPrices
                            join  web_price in mysqlPrices
                            on new { gp_price.ITEMNMBR, gp_price.PRCLEVEL } equals new { web_price.ITEMNMBR, web_price.PRCLEVEL } into outer
                            from o in outer.DefaultIfEmpty()
                            where o == null
                            select new
                            {
                               gp_itemnmbr = gp_price.ITEMNMBR,
                                gp_price = gp_price.PRICE,
                                gp_prclevel = gp_price.PRCLEVEL
                            };
                Console.WriteLine("outer count = " + addquery.Count().ToString());
                
                foreach (var o in addquery)
                {
                    var wp = new webWholeSaleInventoryPrice();
                    wp.ITEMNMBR = o.gp_itemnmbr;
                    wp.MODIFDT = DateTime.Now;
                    wp.PRCLEVEL = o.gp_prclevel;
                    wp.PRICE = o.gp_price;
                    db2.webWholeSaleInventoryPrices.AddObject(wp);
                }

     And the output:

    Filling wholesale price table|
    web prices count = 3535519
    filling GP price tables
    GP prices count = 3553415
    outer count = 3231261

     

    The outer count should be 17,896 I believe...I don't know where it is coming up with 3,231,261 records.  I tried to find a group for LINQ, but I could not, so I'm going to try and post this here. 
    Thanks very much!

    Scott Emick

     


    Euclid Friendly Computer Service
    • Moved by Paul Zhou Thursday, August 11, 2011 7:31 AM (From:.NET Base Class Library)
    • Moved by Martin_Xie Friday, August 12, 2011 3:32 AM Move it to appropriate forum for further support. (From:Off-Topic Posts (Do Not Post Here))
    Tuesday, August 9, 2011 3:51 PM

All replies

  •  

    Hi,

     

    Welcome to the MSDN forum.

     

    According to your description, I'd like to move your thread to off-topic because it is a problem related to LinQ. You may post thread in LINQ to SQL forum. There are more experts in that forum so that you may get more useful help there.

     

    Thank you for your posting and understanding.

    Have a nice day!


    Paul Zhou [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.

    Thursday, August 11, 2011 7:31 AM
  • Hello,

    Thank you for posting.

    From your description, could you please provide more business logics between your entites? I think we should get more detailed information to analyze.

    Please feel free to let me know if you have any finding.

    Thanks,


    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.

    Friday, August 12, 2011 7:12 AM