我不知道为什么Tolist()
不起作用
public partial class Film
{
public int ID { get; set; }
public string Name { get; set; }
public string Mark { get; set; }
public string Genre { get; set; }
internal object ToList()
{
throw new NotImplementedException();
}
}
public Form1()
{
InitializeComponent();
loadTable();
dataGridView.Columns[0].Visible = false;
dataGridView.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
public static IQueryable<Film> Get()
{
var context = new Film_dbEntities();
return (from c in context.Films
where c.Name == "Interstelar"
select new Film{
Name = c.Name,
Mark = c.Mark,
Genre = c.Genre
});
}
public void loadTable()
{
var result = Get().ToList();
dataGridView.DataSource = result;
}
我得到:
“ System.NotSupportedException:'无法在LINQ to Entities查询中构造实体或复杂类型
Film_dbModel.Film
。'”