【发布时间】:2013-11-06 06:02:25
【问题描述】:
我正在使用实体并创建了一个表。
namespace TestExample {
public class Blog
{
public int BlogId {get; set; }
public String Title {get; set;}
public String Description {get; set;}
public virtual Blog Blogs {get; set;}
}
public class BloggingContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
}
class Program
{
static void Main (string[] args) {
var db = new BloggingContext()
// Display all Blogs from the database
var query = (from b in db.Blogs
orderby b.Title
select b).ToList();
foreach (var item in query)
{
//
}
}
}
如何用整个表格填充列表框?当我尝试 Listbox.Datasource = query;我得到奇怪的结果。除了遍历每个项目并打印出 item.Title、item.Description 等之外,还有其他方法吗?
编辑:它是一个 winforms 应用程序。
【问题讨论】:
-
winform 或 wpf。你需要澄清,因为它改变了很多
-
如果您使用 wpf/silverlight,那么您必须使用 ObservalbeCollection
作为属性类型,然后在 xaml 文件中将属性绑定到控件。看看这个stackoverflow.com/questions/19625767/… -
它是一个 Winforms 应用程序
标签: c# .net entity-framework