locked
Some linq queries don't work in lightswitch RRS feed

  • Question

  • I wrote many linq statments and they work just fine in lightswitch.

    But recently I've been pulling my hair out for days trying to work out one LINQ query , and even try it using LinqPad tool, since I rely heavily on using the linqPad tool to make sure that my linq queries are accurate.

    I have a feeling that there is a bug in lightswitch when readinf some linq query.

    Is there any body experiencing this same issue?

    Thanks,

    Rachida


    Rachida Dukes


    • Edited by Rachida Saturday, July 28, 2012 12:41 AM correction
    Saturday, July 28, 2012 12:40 AM

Answers

  • I was able to find what the problem, I use this statment and it works:

    var EntityCol = from o in ObjectContext.Orders
                                from f in ObjectContext.FactoryOrders
                                where  o.OrderKey == f.OrderKey
                                select new TempEntity
                                {
                                    myID = f.FactoryOrderID,
                                    FactoryOrderID =f.FactoryOrderID,
                                    OrderID = o.OrderKey,
                                    OrderDate = o.OrderDate,
                                    Commission = f.Commission.Value,
                                    SalesAmount = f.SalesAmount.Value,
                                };
                     return EntityCol;

     public class TempEntity
        {
            [Key]
            public int myID { get; set; }
            public int FactoryOrderID { get; set; }
            public int OrderID { get; set; }
            public DateTime OrderDate { get; set; }
            public decimal SalesAmount { get; set; }
            public decimal Commission { get; set; }


        }


    Rachida Dukes

    • Marked as answer by Rachida Monday, July 30, 2012 10:40 PM
    Monday, July 30, 2012 10:40 PM

All replies

  • can you post the query that gives trouble ?

    paul van bladel

    Saturday, July 28, 2012 6:59 AM
  • Thanks Paul for taking the time the help, this is the linq query I'm using:

      I have two tables Orders (Parent table) and FactoryOrders (Child table), they're linked by OrderKey which the primary field in the Orders table.

    public IQueryable<SalesmanOrders> GetAllOrdersWithSaleman()

            {

               

                var FactoryOrdersCol = from f in ObjectContext.FactoryOrders

                                       join o in ObjectContext.Orders on f.OrderKey equals o.OrderKey

                                     

                                       select new SalesmanOrders

                                       {

                                        OrderID = o.OrderKey,

                                        OrderDate = o.OrderDate,

                                        ClientName = o.Client.ClientName,

                                        JobName = o.JobName,

                                        Commission = f.Commission.Value,

                                        SalesAmount = f.SalesAmount.Value,

                                       };

        }

    public class SalesmanOrders

        {

            [Key]

            public string myID { get; set; }

            public int OrderID { get; set; }

            public DateTime OrderDate { get; set; }

           public string ClientName { get; set; }

            public string JobName { get; set; }

           public decimal SalesAmount { get; set; }

            public decimal Commission { get; set; }

        }

    I'm using myID field in this query, I'm keeping until for later use.

    Thanks again for your help.

    Rachida


    Rachida Dukes

    Sunday, July 29, 2012 1:00 AM
  • Do you get back zero SalesmanOrders?

    If so, lazy loading might be disabled.

    Also, it might be possible to rewrite your query without a join by using navigation properties.

    Monday, July 30, 2012 3:14 AM
  • This doesn't look like something you'd write in LightSwitch. This looks more like a LINQ query that you would write in a RIA Service.

    It would be helpful if you described what the problem actually is instead of just leaving it at "there's a problem". If an exception occurs, telling us what that exception is and what the call stack is when the exception occurs is extremely useful.


    Justin Anderson, LightSwitch Development Team

    Monday, July 30, 2012 6:30 AM
    Moderator
  • I was able to find what the problem, I use this statment and it works:

    var EntityCol = from o in ObjectContext.Orders
                                from f in ObjectContext.FactoryOrders
                                where  o.OrderKey == f.OrderKey
                                select new TempEntity
                                {
                                    myID = f.FactoryOrderID,
                                    FactoryOrderID =f.FactoryOrderID,
                                    OrderID = o.OrderKey,
                                    OrderDate = o.OrderDate,
                                    Commission = f.Commission.Value,
                                    SalesAmount = f.SalesAmount.Value,
                                };
                     return EntityCol;

     public class TempEntity
        {
            [Key]
            public int myID { get; set; }
            public int FactoryOrderID { get; set; }
            public int OrderID { get; set; }
            public DateTime OrderDate { get; set; }
            public decimal SalesAmount { get; set; }
            public decimal Commission { get; set; }


        }


    Rachida Dukes

    • Marked as answer by Rachida Monday, July 30, 2012 10:40 PM
    Monday, July 30, 2012 10:40 PM