条款返回错误LAMBDA EXPRESSION QUERY

时间:2017-04-30 16:45:02

标签: entity-framework

我有这个

var myvar = _context.Person.Include(u => u.oneByNavigation).Include(u => u.twoNavigation);

 if (!String.IsNullOrEmpty(searchString))
            {
                myvar = dbContext.Where(s => s.Fname.Contains(searchString));// 
                dbContext.Where(u => u.Fname.Contains(searchString) || 
                 u.Lname.Contains(searchString));
            }

我收到错误

*

  

不能将类型system.linq.IQuerable转换为   Microsoft.EntityframeworkCore.Query.IIncludableQuerable

*

2 个答案:

答案 0 :(得分:1)

而不是var myvar = _context.Person[...],请尝试IQueriable<Person> myvar = _context.Person[...]

如果你检查myvar的类型,你会发现它不是IQuariable,而是IIncludableQuerable

答案 1 :(得分:0)

嗯,你被覆盖myvar的值。 试试这个

IQueriable<Person> myvar = _context.Person.Include(u => u.oneByNavigation).Include(u => u.twoNavigation);

 if (!String.IsNullOrEmpty(searchString))
            {
                myvar = myvar // <-- not dbContext
                        .Where(s => s.Fname.Contains(searchString));
            }