错误就像标题所示: 不支持直接绑定到商店查询(DbSet,DbQuery,DbSqlQuery,DbRawSqlQuery)的数据。 我已经我试图寻找可能的修复方法,但无法找到适合我的方法。
这是我的DataLayer:
public virtual IQueryable<T> All()
{
return this.DbSet.AsQueryable();
}
我的控制器:
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;
}
我的GUI就是我所说的:
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();
}
我正在尝试从数据库中获取所有数据并将其发布到ListView中。有人可以查看代码并尝试修复我,如果您需要其他代码,请告诉我。
谢谢,
Marius J。
答案 0 :(得分:0)
我设法修复了我的问题,我创建了一个新的DTO类并编辑了我的控制器:
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;
}