0

There error is as the title states: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery, DbRawSqlQuery) is not supported. I've tried searching for possible fixes, but couldn't find the one that was working for me.

Here is my DataLayer:

public virtual IQueryable<T> All()
{
    return this.DbSet.AsQueryable();
}

My Controller:

public IQueryable<Movie> GetAllMovies()
 {
     var data = this.Data.Movies.All().Select(x => new Movie
     {
         Id = x.Id,
         Name = x.Name,
         ReleaseDate = x.ReleaseDate,
         Rating = x.Rating,
         Duration = x.Duration,
         Director = x.Director,
         Writer = x.Writer,
         Cost = x.Cost,
         Type = x.Type
        }).OrderBy(x => x.Id);

        return data;
    }

And my GUI where I am calling it:

public MovieManagementGUI()
    {
        InitializeComponent();

        ***this.radListView1.DataSource = movieCtr.GetAllMovies();*** //<-- Here I am getting the error
        this.radListView1.ViewType = ListViewType.IconsView;

        this.radListView1.AllowEdit = false;
        this.radListView1.AllowRemove = false;

        ImagePrimitive searchIcon = new ImagePrimitive();
        searchIcon.Alignment = ContentAlignment.MiddleRight;


        SetupIconsView();
    }

I am trying to fetch all the data from the the DB and post it in a ListView. Can somebody look at the code and try fixing me up and if you need additional code, let me know.

Thank you,

Marius J.

MariusJ
  • 83
  • 8
  • what if you returned `data.ToList()` then bind have you tried that..? or If I am not following you try this link for and idea on how to use `IQueryable` http://stackoverflow.com/questions/13109589/how-can-i-return-dbsetentity-asqueryableentitybase-in-mvc4-api-controller. – MethodMan Oct 29 '14 at 21:51

1 Answers1

0

I managed to fix my problem, I created a new DTO class and edited my controller:

    public IEnumerable<MovieDTO> GetAllMovies()
    {
        var data = this.Data.Movies.All().Select(x => new MovieDTO
        {
            Id = x.Id,
            Name = x.Name,
            ReleaseDate = x.ReleaseDate,
            Rating = x.Rating,
            Duration = x.Duration,
            Director = x.Director,
            Writer = x.Writer,
            Cost = x.Cost,
            Type = x.Type
        }).OrderBy(x => x.Id).ToList();

        return data;
    }
MariusJ
  • 83
  • 8