获取可分页列表中的最新活动

发布于 2024-11-19 13:50:56 字数 709 浏览 5 评论 0原文

我正在创建一个网站,在主页上,我想查看最新的更新(最新的评论、活动等..) 这些实体有一个名为 Created (DateTime) 的公共属性。我想从这些活动中获取可分页列表。

我有 3 个解决方案:

  1. 创建一个新的“连接表”:Id、Comment_Id、Event_Id、...、Created。 所以我可以说GetTheLatestActivities(pageSize, pageIndex),当我得到这个列表时,我可以通过导航属性访问实体。这种方法的问题是数据冗余(+1表(和复杂的查询?))

  2. 使用每个层次结构表(TPH):每个“活动”将存储在一个表中,因此我可以轻松过滤记录。这种方法的问题是我的 sql 表方案将被非规范化,并且数据完整性会很弱(因为字段可以为空以支持继承)

  3. 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:

  1. Create a new "join table": Id, Comment_Id, Event_Id, ..., Created.
    So i can say GetTheLatestActivities(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?))

  2. 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)

  3. GetAll entities (Comments, Events etc..), and filter this concatenated list with LINQ (every object support ICreated interface so I can OrderBy Date and use Skip/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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

楠木可依 2024-11-26 13:50:56

您可以创建一个视图来呈现公共字段的并集:

select t1.Table1Id as Id, t1.Name as Description, t1.Job, t1.Created from Table1 t1
union all
select t2.Table2Id as Id, t2.Description, null as Job, t2.Created from Table2 t2

可以将该视图添加到您的模型中,并且您可以对其执行正常的分页“Skip/Take”。

You could create a view that presents a union of the common fields:

select t1.Table1Id as Id, t1.Name as Description, t1.Job, t1.Created from Table1 t1
union all
select t2.Table2Id as Id, t2.Description, null as Job, t2.Created from Table2 t2

This view could be added to your model and you can do the normal paging Skip/Take against it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文