(update: sorry, I removed the AsEnumerable() code because when you use AsEnumerable the linq to sql object executes the sql query and brings the full table to memory which can have more than 10000000 rows and what I wolud like to do is to execute a where in clause) I Am trying to create a “where in” clause in EF (id="EntityFramework" version="6.2.0") in c# to not bring the full table to memory but when used the code below, the select where in clause did not work I know that the DOCUMENT_ID’s that I use exist in the table:
public partial class Table
{
[Key]
[Column(Order = 0)]
public long id { get; set; }
[StringLength(100)]
public string DOCUMENT_ID { get; set; }
public DateTime? xxx { get; set; }
[StringLength(4000)]
public string yyy { get; set; }
public int? zzz { get; set; }
public int? jjj { get; set; }
}
//this is a "patched" code
using (BBDDCon BBDD = new BBDDCon())
{
//this list it is filled with a EF query
idsuptate= new List<String>() {"1","2","3"};
var list_docs_procesed_error_aux = BBDD.Table.Where(d => (d.xxx != null || String.IsNullOrEmpty(d.yyy) || d.jjj != null));
//this one gets me 0 rows but it should bring 300 rows
var list_docs_procesed_error= list_docs_procesed_error_aux.Where(d => idsuptate.Contains( d.DOCUMENT_ID.Trim())).ToList();
}
I found a working solution but as enumerable brings the full table to memory and as I said I would like to not do so:
https://forums.asp.net/t/1661185.aspx?Contains+method+not+working+in+Linq+to+Entities
Use AsEnumerable after the 'tableName' and before applying the 'where' method.
objDataContext = compareIndiaDataContext;
objCProduct = objDataContext.Products.AsEnumerable().Where(db => alSelectedIDs.Contains(db.Product_BrandID)).ToList<Product>();
return objCProduct;
¿Any thoughts? ¿colud be a bug? Thanks a lot in advanced!