English 中文(简体)
Datamodel for a MVC learning project
原标题:

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?

最佳回答

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.

问题回答

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.





相关问题
Datamodel for a MVC learning project

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

Help setting up a data model in Core Data

I am new to Core Data, and have been trying to figure out how to set up my data model. I made a sample table to try and show how I need the data to relate. First Name Last Name Competitor Number ...

implementing core data to an existing iPhone-project

I´ve some trouble with implementing Core Data to my existing iPhone-Project. First I wanna give you a more detailed view on it: Some of my classes are nested into each other: The class "Game" has an ...

REST API / DATA MODEL DESIGN - User , Account or Both Models?

I m having some thoughts about proper building my app and provide a good and consistent API for it but now I m having some doubts about the user/accounts model. It s funny but if you consider some ...

How to map the NHibernate Data Model to the Domain Model?

I started creating a domain model and now I asking myself, how can I map this domain model to a NHibernate Data Model ((using Fluent NHibernate)? Is there anywhere a good and simple example of how to ...

热门标签