how to produce the SQL 'IN' function in the Linq below, then upon the return dataset how to produce the in between data range which is a string value from the dataset.
I want to express logic below in linq
where serialList IN ('serial1', 'serial2', 'serial')
I want to express logic below in linq also for dataFileWriteTime
where dataFileWriteTime >= ''' +
@StartDate + ''' AND dataFileWriteTime <= ''' + @EndDate + ''''
LINQ EXAMPLE: I want to add the above logic to the linq below. Can someone assist me.
var ReportList = (from l in ExampleTable.Enumerable()
where l["TEST_SET_IDENTIFICATION"] == testIdentificationList &&
l["SERIAL_NUMBER"] == serialList &&
l["DATA_WRITE_TIME"] == dateWriteTime &&
select l).ToList();
Loading
Jignesh TrivediPosted Apr 25, 2012, 11:28 PM
For date range your input string must be convert in to date time
Example.
string fromdatestring = "2011-04-26 08:45:00";
string todatestring = "2012-04-26 08:45:00";
DateTime fromdate;
DateTime todate;
var ff = DateTime.TryParse(fromdatestring, out fromdate);
var ft = DateTime.TryParse(todatestring, out todate);
var final = from f in context.Table1
where strings.Contains(f.filedName)
&& f.fromdate >= fromdatestring && f.todate <= todate
select ;
OR
var final1 = Context.Table1.Where(f=>strings.Contains(f.filedName) && f.fromdate >= fromdatestring && f.todate <= todate );
hope this help.
David SmithPosted Apr 25, 2012, 11:31 AM
where dataFileWriteTime >= ''' +
@StartDate + ''' AND dataFileWriteTime <= ''' + @EndDate + ''''
var ReportList = (from l in ExampleTable.Enumerable()
l["DATA_WRITE_TIME"] == dateWriteTime &&
select l).ToList();
Jignesh TrivediPosted Apr 24, 2012, 11:27 PM
For Linq In Query,
First create list of string and use collection.contain method this will create IN query internally.
Example :
List strings = new List();
strings.Add("serial1");
strings.Add("serial2");
strings.Add("serial3");
var final = from f in context.Table1
where strings.Contains(f.filedName)
select f;
var final1 = Context.Table1.Where(f=>strings.Contains(f.filedName);
After that you can add more where conditions.
hope this help.