I working with C# and EF 6.4 and I am looking for clean and easy solution for my problem.
I have simple base like that:
and I want to load data to DataGridView to be looked like that:
I have tried the following solutions:
1
//sorting working, but doesn`t show columns "name" and "title"
Db.BooksAuthors.Include(x => x.Authors).Load();
DataGridView1.DataSource = Db.BooksAuthors.Local.ToBindingList;
2
//sorting not working, but shows columns "name" and "title"
public class BooksAuthorsView
{
public Int32 idBook { get; set; }
public Int32 idAuthor { get; set; }
public string BookTitle { get; set; }
public string AuthorName { get; set; }
}
private void Show()
{
var list = (from BA in Db.BooksAuthors
select new BooksAuthorsView() { idBook = BA.idBook, idAuthor = BA.idAuthor, BookTitle = BA.Books.title, AuthorName = BA.Authors.name });
DataGridView1.DataSource = new BindingSource() { DataSource = new BindingList<BooksAuthorsView>(list.ToList) };
}
EDIT: I checked this solution. It`s working, but is it the simplest solution?