Cannot convert implicitly a type 'System.Linq.IQueryable' into 'Microsoft.EntityFrameworkCore.Query.IIncludableQueryable'
I ran into the same issue. Include produces a new abstraction level on top of IQueryable, called IIncludableQueryable. Your var blogging02Context becomes IIncludeQueryable which is not directly assignable from your Where statement.
Declare your blogging02Context variable as IQueryable<Tag>
instead of var
. It helped in my case.
IQueryable<Tag> blogging02Context = _context.Tag.Include(t => t.Blog);
if (!string.IsNullOrEmpty(Urlid.ToString()))
{
blogging02Context = blogging02Context.Where(t => t.Urlid == Urlid);
}
The compile time error is correct as at the first line you have defined the var blogging02Context
to _context.Tag.Include(....
; This Include
method returns Microsoft.EntityFrameworkCore.Query.IIncludableQueryable
type. Later, you are adding where
clause on the blogging02Context
which returns System.Linq.IQueryable
.
You can update the code with follows:
However, Another point Urlid
is defined as int
so this statement if (!string.IsNullOrEmpty(Urlid.ToString()))
will never be false; as default value of int
would be 0. and 0.ToString()
will be "0".
public async Task<IActionResult> Index(int id,
[Bind("Urlid,Userid,UrlStr,Title")] Url blog, int Urlid)
{
var blogging02Context = _context.Tag.Include(t => t.Blog).Where(t => t.Urlid == Urlid));
ViewBag.Urlid = Urlid;
return View(await blogging02Context.ToListAsync());
}