0

I have 2 tables in one database: first has an information about apatrments, second show what apartments have already booked: has ApatrmentIds from first one, and 2 dates: arrive and departure.

I need to show users what apartments are available to book. It means that user inputs date and apartments dates of book don't match.

Model of first table:

        public class Apartment
        {

            public int ApartmentId { get; set;}

            [Required]
            public int Quantity { get; set; }

            [Required]
            public Classes Class { get; set; }

            [Required]
            public int Price { get; set; }

        }

        public enum Classes
        {
            Economy,
            Standart,
            Luxury
        }

Model of second table:

  public class Booked
    {
        public int BookedId { get; set;}

        public int ApartmentId { get; set; }

        public DateTime Start { get; set; }

        public DateTime End { get; set; }
    }

I tried to use linq, but i need to communicate between ApartmentId(key) of the first table and ApartmentId(not key) of the second.

How it would be better to do?

6
  • Do you really mean different databases or do you mean tables in the same database? What you are showing looks like different tables but you keep mentioning databases. Often these terms can be confusing to those just starting to learn relational database / database design. Commented Nov 5, 2019 at 18:39
  • @Igor, sorry i mean diffrent tables in one database Commented Nov 5, 2019 at 18:44
  • That is a very big difference. What you are looking for is called a "table join", you can also search on entity relationships when searching for Entity Framework solutions. There is a lot of material out there on how to structure these relationships and how to query them. Commented Nov 5, 2019 at 18:45
  • @Igor, yes, i understand that it's a very big diffrence, so what do you think is better to fixed it? Commented Nov 5, 2019 at 18:50
  • 3
    so what do you think is better to fixed it ← Research. Again, there is a lot of material out there including many tutorials and relationships is usually covered early on in any of these sites. All you have to do is spend a little time reading. The above problem can be solved with a trivial amount of effort on your part. Commented Nov 5, 2019 at 18:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.