使用 Code First 的存储库模式在 GridView 中显示多对多关系
我有一个使用 EF 4.1 - Code First 作为数据层的 WebForms 应用程序。我有一个多对多的关系。
public class Application
{
public Application()
{
Administrators = new List<User>();
}
public long Id { get; set; }
public string Name { get; set; }
public virtual ICollection<User> Administrators { get; set; }
}
public class User
{
public User()
{
Administrates = new List<Application>();
}
public long Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Username { get; set; }
// Collections
public virtual ICollection<Application> Administrates { get; set; }
}
假设配置设置正确,是否有一种方法可以实现绑定到 GridView 的 ObjectDataSource,以便显示每个应用程序实体的管理员,每个管理员一个记录行。现在我使用带有视图和 StoredProcs 的 SqlDataSource 来解决这个问题,但我想坚持为我的数据层使用一种架构模式。
I have a WebForms Application using a EF 4.1 - Code First for the Data Layer. I have a many-to-many relationship.
public class Application
{
public Application()
{
Administrators = new List<User>();
}
public long Id { get; set; }
public string Name { get; set; }
public virtual ICollection<User> Administrators { get; set; }
}
public class User
{
public User()
{
Administrates = new List<Application>();
}
public long Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Username { get; set; }
// Collections
public virtual ICollection<Application> Administrates { get; set; }
}
Assuming the configuration is setup correctly, is there a way to implement an ObjectDataSource bound to a GridView in order to show who the administrators are for each application entity, with one record row per administrator. Right now I am using a SqlDataSource with a View and StoredProcs to tackle this problem, but I would like to stick to one architecture pattern for my data layer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
本教程首先使用数据库而不是代码,但有一个示例,该示例看起来与您正在寻找的内容类似,并且可能有一些有用的内容:
http://www.asp.net/web-forms/tutorials/continuing-with-ef/using-the-entity-framework-and-the-objectdatasource-control-part-3-sorting-和-过滤
This tutorial uses database first rather than code first but has an example that otherwise looks similar to what you're looking for and might have something useful:
http://www.asp.net/web-forms/tutorials/continuing-with-ef/using-the-entity-framework-and-the-objectdatasource-control-part-3-sorting-and-filtering