LINQ - LEFT JOIN

4 posts, 0 answers
  1. Neagoe
    Neagoe avatar
    2 posts
    Member since:
    Jul 2010

    Posted 15 Mar 2011 Link to this post

    var Query = from antete_facturi in ZdbContext.AnteteFacturis
                            join adrese_livrare in ZdbContext.AdreseLivrares on new { Idadresalivrare = antete_facturi.IdAdresaLivrare } equals new { Idadresalivrare = adrese_livrare.Id } into adrese_livrare_join
                            from adrese_livrare in adrese_livrare_join.DefaultIfEmpty()
                            select new
                            {
                                Adresalivrare = adrese_livrare.AdresaLivrare,
                                antete_facturi.IdPartener,
                                antete_facturi.NrFactura,
                                antete_facturi.DataFactura
                            };

    Previous linq query work perfect in dbml model, in OA result is null.
    I try to do an evaluation of the product before I buy it, if you have a suggestion to the above problem, please post a reply.
    Best regards,
       Adrian Neagoe
  2. Petko_I
    Admin
    Petko_I avatar
    184 posts

    Posted 21 Mar 2011 Link to this post

    Hello Neagoe,

    Unfortunately, this LINQ scenario with DefaultIfEmpty() is not fully supported yet by OpenAccess. We are working towards improving our LINQ support and this scenario will be one of the first things that we will address. A workaround would be to retrieve the matching joined records in one query and invoke a second query to retrieve the hanging records from the left outer join. Let's consider the following example - we have Orders served by Employees and not every employee has served an order. To get those employees we may first find the rest of the employees who have participated in an order and exclude them from the overall set of the employees:
    IList<int?> employeeServedOrders = context.Orders.Select(x => x.EmployeeID).Distinct().ToList();
    var query = from employee in context.Employees
             where !employeeServedOrders.Contains(employee.EmployeeID)
             select employee;

    We do hope you will find the provided information useful. We will be working on making your example running without extra queries. Should you have further questions, feel free to contact us.

    Best wishes,
    Petko_I
    the Telerik team
  3. DevCraft banner
  4. Karlo
    Karlo avatar
    5 posts
    Member since:
    Oct 2011

    Posted 08 Feb 2012 Link to this post

    Hi Petko_I,

    How can your solution be done when using openaccesslinqdatasource?
  5. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 10 Feb 2012 Link to this post

    Hello Karlo,

    I have prepared a sample application which demonstrates how to achieve that goal using OpenAccessLInqDataSource.
    Hope that helps.

    All the best,
    Damyan Bogoev
    the Telerik team
    Want to use Telerik OpenAccess with SQL Azure? Download the trial version today. 
Back to Top