c# - An unhandled exception of type 'System.StackOverflowException' occurred in EntityFramework.dll -


i getting exception (unhandled exception of type 'system.stackoverflowexception' occurred in entityframework.dll) when tried query large data using linq. code throwing error is,

    if (codelist != null && codelist.count > 0)         {             list<string> codes = codelist.select(x => x.deptcode).distinct().tolist();              namelist = db.legacycodedetails.where(x => x.legacyidentifier.contains(identifier) &&                                                            x.columnabr != null && x.columnabr.equals("name") &&                                                            (codes.where(y => x.legacyidentifier.contains(y)).count() > 0)                                                     )                                                .select(x => new nameandvalue { name = x.value, value = x.legacyidentifier }).distinct().tolist();              list<string> namestodisplay = namelist.select(x => x.name).distinct().tolist(); 

the same code works fine when there hundreds of records. wondering issue.

inner exception: cannot evaluate expression because current thread in stack overflow state

environment:

visual studio 2012, entity framework 6.0, c#, sql server 2008 r2.

question:

am doing wrong linq causing exception? appreciated.

i believe issue occurring because codes large , mixing iqueryable (db.legacycodedetails.where) ienumerable (codes) generated sql contain line every item in codes.

if codes comes table directly access table in query. example:

replace:

codes.where(y => x.legacyidentifier.contains(y)).count() > 0) 

with:

db.codes.select(y => y.deptcode).         .where(y => x.legacyidentifier.contains(y)).any()) 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -