MVC 学习项目的数据模型

发布于 2024-08-26 18:51:55 字数 429 浏览 7 评论 0原文

我正在尝试学习 Microsoft MVC 2,并且在这种情况下找到了一个我想要部署它的小项目。

我的想法是模拟一家可以点餐的餐厅。

基础知识:

  • 用户只能预订整桌, 所以我没有麻烦 合并不同桌子上的人。

    一个人可以订一张桌子 一定的小时数。

我的问题是如何以最智能的方式构建数据模型。我想拥有一个像这样的数据库:

表 { ID, 表名 }

预订 { ID 表ID 保留自 保留至 用户身份 用户

​ { 用户身份 用户名 ... 通过这种方式,

我必须在业务层等中编写大量逻辑,以支持哪些表在什么时间被占用,而不是让数据模型处理它。

那么你们有更好的方法吗?

I am trying to learn Microsoft MVC 2, and have in that case found a small project I wanted to deploy it on.

My idea was to simulate a restaurant where you can order a table.

Basics:

  • A user can only reserve a full table,
    so I don't have the trouble of
    merging people on different tables.

    A person can order a table for a
    certain amount of hours.

My question was how I could make the data model the smartest way. I thought of just having a my database like this:

Table
{
Id,
TableName
}

Reservations
{
Id
TableId
ReservedFrom
ReservedTo
UserId
}

User
{
UserId
UserName
...
}

By doing it this way I would have to program a lot of the logic in e.g. the business layer, to support which tables are occupied at what time, instead of having the data model handle it.

Therefore do you guys have a better way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

梦回旧景 2024-09-02 18:51:55

一种数据库约束,不允许表的两个保留重叠,该函数使用一个函数来计算开始日期时间或结束日期时间位于所插入行的日期时间之间的表的保留数量。该约束将确保计数为 1(刚刚插入的行)。

另外,您应该在用户界面上设置保留所有可用表的阻塞时间。本质上,您将获得当天的所有预订,并为每个小时块计算跨该块的预订数量 - 如果计数等于表的数量,则 UI 不允许该块选择的。这跨越了您的业务/UI 层。

A database constraint that doesn't allow two reservations for a table to overlap using a function that counts the number of reservations for the table whose start datetime or end datetime is between the datetimes of the row being inserted. The constraint would ensure that the count is 1 (the row just inserted).

Also, you should have your user interface block times where all of the tables available are reserved. Essentially, you'd get all the reservations for the day and for each hour block count the number of reservations that span that block -- if the count is equal to the number of tables, then the UI doesn't allow that block to be chosen. This spans your business/UI layers.

等风来 2024-09-02 18:51:55

无法知道一个人需要多长时间才能吃饭,因此您不能假设保留时间是准确的。我会在单独的表中建立时间段。这样就可以使用简单的唯一约束。

TimeSlot { id, StartTime, Duration }

另外,我会转储用户表并仅输入名称。

预订 { id, tableId, date, timeSlotId, Name }

对 { tableId, date, timeSlotId } 施加唯一约束

这可以扩展以允许不同表的不同持续时间,但这超出了我认为的学习项目的范围。

There's no way to know how long a person will take to eat so you cannot assume the ReservedTo time is accurate. I would build up timeslots in a seperate table. That way a simple unique constraint could be used.

TimeSlot { id, StartTime, Duration }

Additionally I would dump the user table and just put in a name.

Reservation { id, tableId, date, timeSlotId, Name }

put the unique constraint on { tableId, date, timeSlotId }

This could be expanded out to allow different durations for different tables but that is outside tke scope of a learning project I think.

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