1. Extension methods
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Linq.Expressions;usingSystem.Reflection;namespaceutils{//http://stackoverflow.com/questions/567963/linq-expression-to-return-property-value/568771#568771 Public Static classcontainsextensions { Public StaticIenumerable<t> Inrange<t, tvalue>( ThisIqueryable<t>Source, Expression<func<t, tvalue>>Selector,intblockSize, IEnumerable<TValue>values) {MethodInfo method=NULL; foreach(MethodInfo tmpinch typeof(Enumerable). GetMethods (BindingFlags.Public|bindingflags.static)) {if(TMP. Name = ="Contains"&&tmp. IsGenericMethodDefinition&& tmp. GetParameters (). Length = =2) {method= tmp. MakeGenericMethod (typeof(TValue)); Break; } } if(Method = =NULL)Throw NewInvalidOperationException ("Unable to locate Contains"); foreach(tvalue[] Blockinchvalues. Getblocks (blockSize)) {varrow = Expression.parameter (typeof(T),"Row"); varmember =Expression.invoke (selector, row); varKeys = expression.constant (block,typeof(tvalue[])); varpredicate =Expression.call (method, keys, member); varLambda = expression.lambda<func<t,BOOL>>(predicate, row); foreach(T recordinchsource. Where (lambda)) {yield returnrecord; } } } Public StaticIenumerable<t[]> getblocks<t>( ThisIenumerable<t> Source,intblockSize) {List<T> list =NewList<t>(blockSize); foreach(T Iteminchsource) {list. ADD (item); if(list. Count = =blockSize) { yield returnlist. ToArray (); List. Clear (); } } if(list. Count >0) { yield returnlist. ToArray (); } } }}
2. Call
Using Utils;
void Test ()
{
var ids=new int[] { 1,2,3 ... 9999 };
var list=datacontext. TestTable. inrange (ee = ee). Id, +, IDS). ToList ();
}
Solution from: http://stackoverflow.com/questions/567963/linq-expression-to-return-property-value/568771#568771
From:http://www.cnblogs.com/xuejianxiyang/p/5491750.html
Extension method solves linqtosql contains more than 2100 lines error problem