Some linq queries don't work in lightswitch
-
samedi 28 juillet 2012 00:40
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
- Modifié Rachida samedi 28 juillet 2012 00:41 correction
Toutes les réponses
-
samedi 28 juillet 2012 06:59can you post the query that gives trouble ?
paul van bladel
-
dimanche 29 juillet 2012 01:00
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
-
lundi 30 juillet 2012 03:14
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.
-
lundi 30 juillet 2012 06:30Modérateur
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
-
lundi 30 juillet 2012 22:40
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
- Marqué comme réponse Rachida lundi 30 juillet 2012 22:40

