gridview 的简单 EF 查询?
总体 ef 新手问题 - 给定这个简单的实体模型,我将如何设置一个简单的查询来在网格视图中显示所有客户端?或者显示给定范围内邮政编码的所有客户端?
public class scheduleContext : DbContext
{
public DbSet<client> clients { get; set; }
public DbSet<appt> appts { get; set; }
}
public class client
{
public int clientID { get; set; }
public String name { get; set; }
public String email { get; set; }
}
public class appt
{
public int apptID { get; set; }
public int clientID { get; set; }
public DateTime date { get; set; }
}
...
scheduleContext schedule = new scheduleContext();
var q = from p in schedule.appts where select p; //this throws an error
GridView1.DataSource = schedule.appts.Load(); //load what??
GridView1.DataBind();
Total ef newbie question - given this simple Entity Model, how would I set up a simple query to display all clients in a gridview? Or display all clients with a zip in a given range?
public class scheduleContext : DbContext
{
public DbSet<client> clients { get; set; }
public DbSet<appt> appts { get; set; }
}
public class client
{
public int clientID { get; set; }
public String name { get; set; }
public String email { get; set; }
}
public class appt
{
public int apptID { get; set; }
public int clientID { get; set; }
public DateTime date { get; set; }
}
...
scheduleContext schedule = new scheduleContext();
var q = from p in schedule.appts where select p; //this throws an error
GridView1.DataSource = schedule.appts.Load(); //load what??
GridView1.DataBind();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用 EntityDataSource 控件?使用此控件允许您使用 LINQ 查询对象模型并支持网格视图中的分页和排序。
让我们看一个示例:
有许多不同的方法来配置 EntityDatasource 允许您设置过滤器、选择特定列等。
有很多关于这些控件的示例和提示,这些只是其中的一些:
Have you tried using an EntityDataSource control? Using this control allows you to use LINQ to query your object model as well as support paging and sorting within your grid view.
Let's look at an example:
There are many different ways to configure the EntityDatasource to allow you do set filters, select specific columns, etc.
There are plenty of examples and tips regarding these controls, these are just a few: