0

I have the following code:

var q = context.Fuels.AsQueryable();
if (dateEdit1.EditValue != null && dateEdit2.EditValue != null)
{
   q.Where(d => d.FuelDate >= dateEdit1.DateTime && d.FuelDate <= dateEdit2.DateTime);
}

and it's working, it will get all rows in table.

but when I'm using this code:

if (dateEdit1.EditValue != null && dateEdit2.EditValue != null)
{
     var r = context.ExecuteStoreQuery<Fuel>(String.Format("SELECT * FROM Fuel WHERE FuelDate BETWEEN '{0}' AND '{1}'", 
                 dateEdit1.DateTime.Year + "-" + dateEdit1.DateTime.Month + "-" + dateEdit1.DateTime.Day, 
                 dateEdit2.DateTime.Year + "-" + dateEdit2.DateTime.Month + "-" + dateEdit2.DateTime.Day));
}

it's working but I need to use the first way to get relations working.

Any idea what is the problem in the first one?

4

1 回答 1

3

在您的 if 子句中,您需要将其分配给 q,如果您不这样做,则 q 只是对所有人的查询Fuels

这应该有效:

q = q.Where(d => d.FuelDate >= dateEdit1.DateTime && d.FuelDate <= dateEdit2.DateTime);
于 2013-11-07T18:26:43.267 回答