I have defined the following Model
public class TodayOrder
{
public string ID_ORIG { get; set; }
public string PART_ID { get; set; }
public string PART_DEX { get; set; }
public double TimeSecs { get; set; }
}
and now I am trying to populate a List using the following Linq expression:
var todaysOrders = DCC.vw_ORD_GP_volumes_lastSets
.Where(a => a.ID_ORIG == id_orig.ToUpper() &&
a.PART_ID == Part.ToUpper())
.Select(a =>
new TodayOrder{
ID_ORIG = a.ID_ORIG,
PART_ID = a.PART_ID,
PART_DEX = a.PART_DEX,
TimeSecs = a.ReqTime.GetValueOrDefault().TotalSeconds });
List<TodayOrder> lst = todaysOrders.ToList();
where ReqTime is of type TimeSpan?.
The problem is that at runtime I am getting an error Value has no literal in SQL: 00:00:00 – looks like there is a problem with the TimeSpan.
Line 72: });
Line 73: ERROR> lst = todaysOrders.ToList();
Line 74:
[InvalidOperationException: Value has no literal in SQL: 00:00:00]
System.Data.Linq.SqlClient.Visitor.FormatValue(Object value) +584911
System.Data.Linq.SqlClient.Visitor.VisitValue(SqlValue value) +32
In facts, if I comment out the line setting the property TimeSecs everything is working fine.
What would be the right approach to instantiate the TodayOrder class instances?
The problem is that Linq-to-Sql treis to translate the expression
a.ReqTime.GetValueOrDefault().TotalSecondsto sql but it fails.You can solve it by evaluating the query with a
ToArray()before the select and do the select on the client side: