Click here to Skip to main content
14,430,746 members
Rate this:
Please Sign up or sign in to vote.
i am creating a dashboard in mvc c# using entity framework

I have two tables

the output i want to display be like : (Id,Channel_Name,News_Title,News_Description).

I got the following error :
Cannot implicitly convert type 
                 'System.Collections.Generic.IEnumerable<xxx>' to 

What I have tried:

Model Class:
public class ShowData
    public List<Tbl_Channel> tbl_ChannelData { get; set; }
    public List<Tbl_News> tbl_NewsData { get; set; }

Controller Class :

 public ActionResult Dashboard()
 ShowData model = new ShowData();
  var rs1 = (from c in db.Tbl_Channel select c).ToList();

  var rs2 = (from c in db.Tbl_News join d in db.Tbl_Channel on c.Channel_Id
             equals d.Id select new
          .OrderByDescending(x => x.Id)

       model.tbl_ChannelData = rs1;
       model.tbl_NewsData = rs2;

      return View(model);
Updated 19-Apr-19 22:16pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1


That should be a ., not a >

The only reason to call ToList is to ensure that the query runs before it goes stale. There's no reason for that not to work that I can see. Might using a dynamic be the issue? What if you create a class to use?

Otherwise, just use foreach to make your own list and at a minimum, start to filter down what the issue is
Umair Nafis 20-Apr-19 3:16am
@christian Graus Thank you for the reply sir , here i updated my code kindly review it. im still getting the same error
Christian Graus 20-Apr-19 4:01am
You've completely failed to do the things I suggested in order to try to break down the source of the error.....

Stop calling ToList. You have two queries, which one fails? What if you iterate over your IEnumerable and build your own list?
Christian Graus 20-Apr-19 4:01am
You also have failed to create an entity class to see if that's the issue.

