user2545071
user2545071

Reputation: 1410

Can i filter Table from LinqToSQL?

Good day!

I load some big table via LinqToSql. Can i download part of this table? For example, load table where row.dt<=some_date_time?

I do it like this:

Infrastructure.Table = Globals.DataContext.GetTable<SomeTable>();

But is still very big - 100 000+ rows.

Can i do like that:

DateTime filterDate=new DateTime(2014,5,1,0,0,0);
Infrastructure.Table = Globals.DataContext.GetTable<SomeTable>().Where(item=>item.dt<=filterDate);

I cannot do that,because i shoud cast it to IQueryable. This result table contains only rows that item.dt<=filterDate?

i try to get less table as i can

So,how to filter this table via date time? and cast it to System.Linq.Table?

Thank you!

Upvotes: 0

Views: 117

Answers (1)

ntl
ntl

Reputation: 1299

What is the problem to cast Table to IQueryable?

You can do something like:

DateTime filterDate=new DateTime(2014,5,1,0,0,0);
var query = ((IQueryable<SomeTable>)dc.GetTable<SomeTable>()).Where(item => item.Date < filterDate);
var filteredItems = query.ToList();

Note that in this exmaple data will be filtered on DB side, and not all 100 000+ rows will be fetched from DB.

Upvotes: 1

Related Questions