获取可分页列表中的最新活动
我正在创建一个网站,在主页上,我想查看最新的更新(最新的评论、活动等..) 这些实体有一个名为 Created
(DateTime
) 的公共属性。我想从这些活动中获取可分页列表。
我有 3 个解决方案:
创建一个新的“连接表”:
Id、Comment_Id、Event_Id、...、Created
。 所以我可以说GetTheLatestActivities(pageSize, pageIndex)
,当我得到这个列表时,我可以通过导航属性访问实体。这种方法的问题是数据冗余(+1表(和复杂的查询?))使用每个层次结构表(TPH):每个“活动”将存储在一个表中,因此我可以轻松过滤记录。这种方法的问题是我的 sql 表方案将被非规范化,并且数据完整性会很弱(因为字段可以为空以支持继承)
GetAll 实体 (
Comments
,事件
等..),并使用LINQ过滤这个串联列表(每个对象都支持ICreated
接口,因此我可以OrderBy
日期和使用跳过/继续
)。明显的问题是性能,我会在每个请求中从数据库获取所有记录,并在“客户端”进行过滤。
我觉得第一个最好,或者还有什么更好的解决方案吗?
谢谢
I'm creating a website and on the main page, I want to see the latest updates (latest comments, events, etc..)
These entities have a common property called Created
(DateTime
). I want to get a pageable list from these activities.
I have 3 solutions:
Create a new "join table":
Id, Comment_Id, Event_Id, ..., Created
.
So i can sayGetTheLatestActivities(pageSize, pageIndex)
and when I get this list I can access the entities via navigation properties. The problem with this approach is the data redundancy (+1 table (and complicated query?))Using Table per Hierarchy (TPH): every "activities" would be stored in one table, so I can filter the records easily. The problem with this approach is my sql table scheme would be denormalized, and the data integrity would be weak (because of the fields would be nullables to support inheritance)
GetAll entities (
Comments
,Events
etc..), and filter this concatenated list with LINQ (every object supportICreated
interface so I canOrderBy
Date and useSkip/Take
). The obvious problem is the performance, I would get all of the records from the db in every requests, and filter on the "client side".
I think the best is the first one, or are there any better solution?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个视图来呈现公共字段的并集:
可以将该视图添加到您的模型中,并且您可以对其执行正常的分页“Skip/Take”。
You could create a view that presents a union of the common fields:
This view could be added to your model and you can do the normal paging Skip/Take against it.