Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Cannot return Data from query - IEnumerable IQueryable

$
0
0

Hello 

I am trying to return the data from two tables in two different DBcontext. 

When I use this code 

            var mytable= _context.mytable;
            var Appuser = _adbcontext.Users;


            var query = (from e in Appuser
                                     join o in mytable on e.Id equals o.CreateByUserId
                                     select new
                                     {
                                         o.companyname,
                                         o.AdminId,
                                         o.Tid,
                                         o.StartDate,
                                         o.EndDate,
                                         o.CreateByUserId,
                                         o.ModifiedByUserId,
                                         o.CreatedOnDate,
                                         o.ModifiedOnDate,
                                         e.FullName
                                     });

 return View(query.AsEnumerable());

In result view, I can see that the query can select the records 

I used this too 

 return View(query.Tolist());

also doesn't work 

I am getting 

InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable ViewDataDictionary instance requires a model item of type 'System.Collections.Generic.IEnumerable

I read many posts that Changing the @model IEnumerable<webapp.Models.mytable> to List Instead of IEnumerable 

That doesn't work too.

I added 

AsQueryable()  to 

var mytable= _context.mytable.AsQueryable();
var Appuser = _adbcontext.Users.AsQueryable();

and Also 

var mytable= _context.mytable.ToAsyncEnumerable();
var Appuser = _adbcontext.Users.ToAsyncEnumerable();

All not working 

While this is working 

var query= _context.mytable;

but this is only returning data from one table and I need from two 

any idea? 


Viewing all articles
Browse latest Browse all 9386

Trending Articles